このスクリプトは上から下に線を描いていますが、マウスオーバー "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>