我有一个漂亮的css切换控件,我正在尝试为它添加卷帘支持,并且我正在使用TouchSwipe插件。问题是我不知道如何只影响调用它的元素。我在页面上有一堆切换,现在它们都被触发了,而不仅仅是我在上面滑动的那个。(touchswipe插件:http://labs.rampinteractive.co.uk/touchSwipe/demos/)
例如,下面的代码:
/* Toggle */
$('.toggle2').click(function() {
/* code which switches between toggled on and toggled off */
}).disableSelection().swipe({
_this: $(this),
swipeLeft: function(event, direction, distance, duration, fingerCount, fingerData){
if ($('.toggle2').hasClass('on'))
$('.toggle2').trigger('click');
},
swipeRight: function(event, direction, distance, duration, fingerCount, fingerData){
if ($('.toggle2').hasClass('off')) alert('n');
$('.toggle2').trigger('click');
},
threshold: 0
});工作,但它触发了我在页面上的所有切换。我尝试将$('.toggle2')更改为$(event.target),但无济于事。我做错了什么?
发布于 2014-12-10 06:32:47
尽管您在问题中没有分享太多,但看起来所有其他切换都将toggle2作为它们的类(<div class="toggle2"></div>)。将另一个添加到您正在尝试滑动的(<div class="toggle2 toggle-swipe"></div>),并将其用于您的卷帘脚本:
$('.toggle-swipe').click(function() {
/* code which switches between toggled on and toggled off */
}).disableSelection().swipe({
// ...
});https://stackoverflow.com/questions/27389906
复制相似问题