[英]jQuery sliding of div
So, my code is supposed to move the pink coloured div to position 'right : 10px;'所以,我的代码应该将粉红色的 div 移动到“right : 10px;”的位置yet it is not working.
但它不起作用。 here is the Fiddle for it.
这是它的小提琴。 All replies will be appreciated.
所有答复将不胜感激。
HTML: About HTML:关于
<div id="aboutSector"></div>
jQuery: jQuery:
function aboutShow() {
$("#aboutSector").animate({ right: "10px" }, "fast");
};
CSS: CSS:
#navBar {
width: 80%;
height: 40px;
left: 10%;
top: 0px;
position: absolute;
box-shadow: 0 2px 2px -2px black;
}
Your code has obtrusive java script in it.您的代码中包含引人注目的 Java 脚本。 Instead of having an
onclick
event, I put an event listener on it.我没有使用
onclick
事件,而是在其上放置了一个事件侦听器。 You're fiddle also didn't have jQuery on it, so I've added that in my updated fiddle .你的小提琴也没有 jQuery,所以我在我更新的 fiddle 中添加了它。
The HTML HTML
<div id="navBar">
<button id="aboutButton">About</button>
</div>
<div id="aboutSector"></div>
The jQuery: jQuery:
$(document).ready(function() {
$("#aboutButton").click(function() {
$("#aboutSector").animate({ right: "10px" }, "fast");
});
});
You had an an undefined
error in your original code.您的原始代码中有一个
undefined
错误。 If you wanted to get fancy, you can slide it back after the next click.如果您想花哨,可以在下次单击后将其滑回。
The jQuery jQuery
$(document).ready(function() {
$("#aboutButton").click(function() {
var right = $("#aboutSector").css("right"),
shifter = (right == "10px") ? "0px" : "10px";
$("#aboutSector").animate({ right: shifter }, "fast");
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.