该脚本从上到下绘制一条线,但它从鼠标悬停“onhover”开始,我希望它在打开页面时绘制它。
这是要清楚的整个代码。它唯一的功能就是从这条线上悬停$( this ).hover(function()
。
var animationDuration = "0.4"
var backgroundColor = "white"
$.fn.line = function liner(animationDuration, borderWidth, side, backgroundColor) {
var className = "line"
var timePerSide = animationDuration
$(this).append('<div class=' + className + '> <div></div> </div>');
$(this).children("." + className).css({
"-webkit-transition": "all " + timePerSide + "s linear " + timePerSide * 0 + "s",
"transition": "all " + timePerSide + "s linear " + timePerSide * 0 + "s",
"background-color": backgroundColor,
});
switch (true) {
case side == "right":
$(this).children(".line").css({
"top": "0",
"right": "-10",
"height": "0%",
"width": borderWidth,
});
}
if (side == "right") {
$(this).hover(function () {
$(this).children(".line").css({
"height": "150%",
});
});
}
};
这是我的 HTML
<body>
<div class="box1 float-left liner">
<h1>Lorem</h1>
</div>
</body>
<script type="text/javascript">
$( document ).ready(function() {
$('.liner').line(animationDuration, "5px", "right", backgroundColor);
});
</script>
</html>