【发布时间】:2014-09-20 15:39:36
【问题描述】:
我制作了一个 jQuery 切换,用户可以在其中选择主题的宽度,使其变得流畅或使用切换按钮固定。 事情工作正常,但我想添加单独的切换按钮,一个用于单击时固定宽度,另一个用于单击时流体宽度。
我试过了,但我没有成功。
这是我使用的代码
$(document).ready(function () {
var setWidth = $.cookie("width");
if (typeof setWidth !== "undefined" && setWidth == "85%") {
$('#container,.wrp').width(setWidth); // 85% width set using cookie
} else if (typeof setWidth !== "undefined" && setWidth == "960px") {
$('#container,.wrp').width(setWidth); // 960px,1000px(for wrp) width set using cookie
}
$('#toggle-button').click(function () {
var toggleWidth = $("#container").width() == 960 ? "85%" : "960px";
$('#container, .wrp').animate({
width: toggleWidth
});
$.cookie('width', toggleWidth);
});
});
这里是小提琴:http://jsfiddle.net/envira/kTrLL/
谢谢。
【问题讨论】:
标签: jquery cookies width toggle