我有一个jQuery脚本,从右到左滑动一个名为.inner的div。但问题是,它将使用类.inner切换所有div。我要做什么来切换.next().inner?
$(document).ready(function() {
// This will fire when document is ready:
$(window).resize(function() {
// This will fire each time the window is resized:
if($(window).width() <= 768) {
// if larger or equal
$(".myButton").click(function () {
// Set the effect type
var effect = 'slide';
// Set the options for the effect type chosen
var options = { direction: $().val('right') };
// Set the duration (default: 400 milliseconds)
var duration = 500;
$('.inner').toggle(effect, options, duration);
});
} else {
// if smaller
$('.element').hide();
}
}).resize(); // This will simulate a resize to trigger the initial run.
});
谢谢
编辑:
HTML:
<div class="col-xs-1 col-md-1">
<span class="glyphicon glyphicon-th-list icons-popover myButton" data-html=true data-popover="true" data-content="
<div class='actions'>
<a href='#' data-toggle='tooltip' data-placement='top' title='Something'><span class='glyphicon glyphicon-file'></span></a>
</div>">
</span>
</div>
<div class="inner" style="margin-left: 0px;">
// somethinh
</div>
<div class="close myButton"><span class='glyphicon glyphicon-remove'></div>
答案 0 :(得分:0)
$(this).next('.inner').toggle(effect, options, duration);
答案 1 :(得分:0)
我找到了答案:
$(".myButton").click(function () {
// Set the effect type
var effect = 'slide';
// Set the options for the effect type chosen
var options = { direction: $().val('right') };
// Set the duration (default: 400 milliseconds)
var duration = 500;
$(this).parent().next('.inner').toggle(effect, options, duration);
});
$(".close").click(function () {
// Set the effect type
var effect = 'slide';
// Set the options for the effect type chosen
var options = { direction: $().val('right') };
// Set the duration (default: 400 milliseconds)
var duration = 500;
$(this).parent('.inner').toggle(effect, options, duration);
});