我有一个脚本正在处理屏幕宽度-225px但是我想改变,当屏幕命中1100px,使该功能只是使用整个宽度。在不同的屏幕尺寸更改jQuery功能
这里是我使用的代码:
function slide_holder(){
$('#main').css({'width': (($(window).width()) - 225)+'px'});
$('.flexslider-container').css({'height': (($(window).height()) - 85)+'px', 'width': (($(window).width()) - 225)+'px'});
$('.flexslider').css({'height': (($(window).height()) - 275)+'px'});
$('#tS3').css({'height': (($(window).height()) - 200)+'px'});
$('#foot').css({'width': (($(window).width()) - 325)+'px'});
}
这是它的调用方式:
$(document).ready(function() {
slide_holder();
$(window).bind('resize', slide_holder);
});
我曾想过尝试像这样,但我有一个大失败:
$(window).bind("resize", resizeWindow);
function resizeWindow(e){
var newWindowWidth = $(window).width();
// If width width is below 600px, switch to the mobile stylesheet
if(newWindowWidth < 1100){
function slide_holder(){
$('#main').css({'width': (($(window).width()) - 0)+'px'});
$('.flexslider-container').css({'height': (($(window).height()) - 85)+'px', 'width': (($(window).width()) - 0)+'px'});
$('.flexslider').css({'height': (($(window).height()) - 275)+'px'});
$('#tS3').css({'height': (($(window).height()) - 200)+'px'});
$('#foot').css({'width': (($(window).width()) - 105)+'px'});
}
}
// Else if width is above 600px, switch to the large stylesheet
else if(newWindowWidth > 1100){
function slide_holder(){
$('#main').css({'width': (($(window).width()) - 225)+'px'});
$('.flexslider-container').css({'height': (($(window).height()) - 85)+'px', 'width': (($(window).width()) - 225)+'px'});
$('.flexslider').css({'height': (($(window).height()) - 275)+'px'});
$('#tS3').css({'height': (($(window).height()) - 200)+'px'});
$('#foot').css({'width': (($(window).width()) - 325)+'px'});
}
}
}
你会更好地使用CSS媒体查询这个... – elclanrs 2012-02-08 03:29:45
_“但我得到了一个很大的失败” - - 在某种意义上?你是否收到错误信息,它是否不运行,它运行但是做错了什么? – nnnnnn 2012-02-08 03:34:39
我同意elclanrs。去年我参加了一个设计会议,其中一位发言人讨论了“响应式网页设计”,即创建一个响应正在渲染的设备的网站。通过使用elclanrs评论过的媒体查询,您可以轻松构建响应浏览器中更改的页面。查看此URL以查看某些人对响应式网页设计所做的一些示例:http://designmodo.com/responsive-design-examples/尽管它没有回答您的问题,但它确实为您提供了一些有关即将到来的视图的信息移动为网络设计 – 2012-02-08 04:14:26