当手机从纵向旋转到横向时,如何动态更改使用 jQuery 设置的内容 slider 的宽度和高度?客户正在为其站点使用“allinone”内容 slider 。此内容 slider 的宽度和高度是使用 jQuery 和以下代码设置的:
jQuery(function() {
jQuery('#allinone_contentSlider_imposing').allinone_contentSlider({
width: 300,
height: 300
});
});
我想在手机从纵向切换到横向时动态更改 slider 的宽度和高度,但我的 javascript 技能不够好。我尝试使用 $(window).width() 和 resize() 事件定义变量,但没有成功:
jQuery(function() {
function updateWidth() {
var $containerWidth = $(window).width();
}
updateWidth();
$(window).resize(function() {
updateWidth();
});
jQuery('#allinone_contentSlider_imposing').allinone_contentSlider({
width: $containerWidth,
height: 300
});
});
不幸的是,上面的代码未能定义导致 slider 不显示的宽度。顺便说一句,这不是一个仅限移动设备的网站。也许有更好的方法来解决这个问题。接受建议。
最佳答案
jQuery(文档).ready(函数(){
vp_width = jQuery(window).width();
if (vp_width <= 650) {
//alert('mobile');
//Add some Jquery here to change the height and width of the banner?
)};
不确定这是否有帮助,如果您知道设备的宽度,您或许可以像上面那样定位宽度,然后设置一些 CSS?希望这会有所帮助,如果没有,我们深表歉意!
关于jquery - 使用 jquery 动态更改移动内容 slider 宽度以进行纵向和横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16816880/