我试图执行javascript函数 - 仅在特定div中执行onload,但我被卡住了,所以如果有人可以帮助我,请。非常感谢您提前
function dropsFall() {
}

.drop {
display: block;
min-height: 280px;
overflow: hidden;
}

<div class="row">
<div class="col-xl drop"></div>
</div>
&#13;
答案 0 :(得分:1)
这段代码在指定的div(就像容器)中执行动画:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<style>
.rectangle
{
width: 300px;
height: 20px;
display: block;
position: relative;
border: 1px solid black;
margin: 20px 0;
}
.square-small
{
display: block;
width: 20px;
height: 20px;
position: absolute;
background-color: green;
}
</style>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script>
$('body').ready(function(){
$('.rectangle')
.find('.square-small')
.animate({
left: $('.rectangle').width() - $('.rectangle').find('.square-small').width()
}, 'slow');});
</script>
<div class="rectangle">
<div class="square-small"></div>
</div>
</body>
</html>
答案 1 :(得分:0)
你想在点击事件中添加div中的drop class吗?
<div class="row">
<div class="col-xl" onclick="dropsFall(this)"></div>
</div>
答案 2 :(得分:0)
将div ID作为参数传递给函数,并使用if语句检查它是否是必需的div
function dropsFall(my_div) {
if(my_div==‘your required div’){
//your code will be here
}
}
答案 3 :(得分:0)
那么为什么不在div
内写下你的脚本,如下所示:
<div class="row">
<div class="col-xl drop">
<script>dropsFall()</script>
</div>
</div>