点击,点击不工作?jquery
onclick, click not working? jquery
我只是想改变一个悬停触发点击,但由于某种原因,我使用的任何点击功能不工作?
这是我当前的代码,当你悬停…
当前脚本工作在悬停…
$showSidebar.hover(function() {
$wrapper.stop().animate({ left: "-178px" }, 300);
$sidebarSlider.stop().animate({ width: "452px" }, 300);
$latestTweet.stop().animate({width: "452px", top : "-1px", backgroundColor: "#464848" }, 300);
}, function() {
$wrapper.stop().animate({ left: "0" }, 300);
$sidebarSlider.stop().animate({ width: "274px" }, 300);
$latestTweet.stop().animate({ top : "-1px", width: "274px", backgroundColor: "#464848" }, 300);
});
但是看看我下面的尝试让它在点击时工作,但奇怪的是什么也没有发生。
My Attempt One
$showSidebar.click(function() {
$wrapper.stop().animate({ left: "-178px" }, 300);
$sidebarSlider.stop().animate({ width: "452px" }, 300);
$latestTweet.stop().animate({width: "452px", top : "-1px", backgroundColor: "#464848" }, 300);
}, function() {
$wrapper.stop().animate({ left: "0" }, 300);
$sidebarSlider.stop().animate({ width: "274px" }, 300);
$latestTweet.stop().animate({ top : "-1px", width: "274px", backgroundColor: "#464848" }, 300);
});
和
第二次尝试
$showSidebar.on('click', function () {
$wrapper.stop().animate({ left: "-178px" }, 300);
$sidebarSlider.stop().animate({ width: "452px" }, 300);
$latestTweet.stop().animate({width: "452px", top : "-1px", backgroundColor: "#464848" }, 300);
}, function() {
$wrapper.stop().animate({ left: "0" }, 300);
$sidebarSlider.stop().animate({ width: "274px" }, 300);
$latestTweet.stop().animate({ top : "-1px", width: "274px", backgroundColor: "#464848" }, 300);
});
和其他几个,但nudda…
这是我的标记…
<a href="#" title="More" class="button blu large" id="show-sidebar"><span>//</span> MORE</a>
和我的变量
$showSidebar = $("#show-sidebar");
你知道我哪里错了吗?非常有帮助,谢谢!
查看工作代码,谢谢@hurshagrawal
$showSidebar.on('click', function () {
if ($showSidebar.html() == '<span>//</span> CLOSE') {
$wrapper.stop().animate({ left: "0" }, 300);
$sidebarSlider.stop().animate({ width: "274px" }, 300);
$latestTweet.stop().animate({ top : "-1px", width: "274px", backgroundColor: "#464848" }, 300);
} else {
$wrapper.stop().animate({ left: "-178px" }, 300);
$sidebarSlider.stop().animate({ width: "452px" }, 300);
$latestTweet.stop().animate({width: "452px", top : "-1px", backgroundColor: "#464848" }, 300);
$showSidebar.html('<span>//</span> CLOSE');
}
});
我想你是在找。toggle()命令:
$showSidebar.toggle(function() {
$wrapper.stop().animate({ left: "-178px" }, 300);
$sidebarSlider.stop().animate({ width: "452px" }, 300);
$latestTweet.stop().animate({width: "452px", top : "-1px", backgroundColor: "#464848" }, 300);
}, function() {
$wrapper.stop().animate({ left: "0" }, 300);
$sidebarSlider.stop().animate({ width: "274px" }, 300);
$latestTweet.stop().animate({ top : "-1px", width: "274px", backgroundColor: "#464848" }, 300);
});
我不认为$.click()需要2个函数作为参数。你试过把第二个函数提出来吗?如果你试图在这两者之间切换,你可能需要写一些带有If -else语句的东西。
编辑:啊,或者使用。toggle()。
尝试使用bind(),我发现跨浏览器更可靠。
http://api.jquery.com/bind/在您的情况下的基本用法是(未经测试):
$showSidebar.bind('click', function() {
// do stuff
});
相关文章:
- 不正确的工作jquery插件bxslider与插件elevatezoom
- 更改图像src-dons't工作jquery/js
- event.prventDefault()不工作(jQuery实时)
- delay()不会'第二次工作jquery
- 如何工作 jQuery 就绪
- 几天后,昨天停止工作jQuery
- .click() 不再工作 jquery.
- 如何使工作jquery"“滑动”;在iPad上滚动
- 为什么不是't这个选择器正在工作(Jquery和Asp.net)
- Flexslider无法在html网站中工作(jQuery无法加载?)
- 点击,点击不工作?jquery
- 按钮在“加”和“减”之间切换,需要“点击”;只能在fa +上工作.jQuery
- 突出显示搜索列表不工作(jquery问题)
- 页眉内的Div /靠近页面顶部/在2次点击事件后不显示,而它的's页脚双胞胎工作- jquery
- 为什么css后台jQuery代码不工作jQuery设置多个css值
- .stop()不是't使用我的悬停,使快速移动工作-jQuery
- 自定义验证方法不工作- jQuery验证插件
- 数据表columnDefs不工作:jquery / javascript
- 工作jQuery代码赢得'不要在电话间隙跑步
- 我的Javascript代码不工作- Jquery选择器问题