Javascript 基于浏览器宽度动态设置插件属性
我目前正在一个项目中实现,滑块具有以下可选设置Javascript 基于浏览器宽度动态设置插件属性,javascript,jquery,Javascript,Jquery,我目前正在一个项目中实现,滑块具有以下可选设置 $("#accordion").awsAccordion({ type: "horizontal", cssAttrsHor: { ulWidth: "responsive", liHeight: 500, liWidth: 50 }, cssAttrsVer: { ulWidth: "responsive" }, startSlide:
$("#accordion").awsAccordion({
type: "horizontal",
cssAttrsHor: {
ulWidth: "responsive",
liHeight: 500,
liWidth: 50
},
cssAttrsVer: {
ulWidth: "responsive"
},
startSlide: 2,
openCloseHelper: {
openIcon: "plus",
closeIcon: "minus"
},
openOnebyOne: true,
classTab: "small",
slideOn: "click",
autoPlay: true,
autoPlaySpeed: 3000
})
上面写着:类型:水平,
我想将其更改为:type:vertical,
当浏览器宽度低于768px时,这是否可行。这可以通过使用变量设置type属性来实现
var type = 'horizontal'; // Default type
if ($(window).width() < 768) {
type = 'vertical'; // When window width is less than 768, make type vertical
}
$("#accordion").awsAccordion({
type: type, // Use variable here
...
});
试着使它变为变量
$(function(){
var x;
if(window.width<786){
x = "vertical";}else{
x= "horizontal";}
});
谢谢你,我确实有一个例子,但你会笑的!当我有你的注意,它可以设置,使其变回以前的类型时,浏览器回到更广泛的768,再次感谢您的帮助。我猜是另外一个statement@webmonkey237只需在on resize方法中放入另一个条件:$window.on'resize',函数{…};感谢您的帮助,我补充说,再次工作得很好,看起来它需要刷新才能正确地重新加载脚本,而它的功能/滑动在浏览器窗口调整时会变得非常疯狂,我应该能够使用您提供的。再次感谢,如果您将它括起来,它将成为一个字符串而不是一个变量
$(function(){
var x;
if(window.width<786){
x = "vertical";}else{
x= "horizontal";}
});
$("#accordion").awsAccordion({
type: x ,
cssAttrsHor:{
ulWidth:"responsive",
liHeight:500,
liWidth:50
},