我一直在使用这个站点作为资源,而我学习了一些jQuery。我的技能水平主要是整合和修改其他人的代码。到现在为止还挺好。 我有一个问题,并注册了,所以我可以发一个问题。
基本上,我有一个设计宽度为1280像素的网站。我正在使用jQuerytools的“标签”和“可滚动”插件来获得一个4000px +水平图像滚动内容。 当然,在1080p屏幕上,“可滚动”窗格未到达屏幕的两侧。 我的解决方案是我发现如果宽度大于1280px则缩放页面的脚本。
这是代码。
$().ready(function() {
var currentWidth = $(document.body).width();
var targetWidth = 1280; // experiment for your self
var scrollWidth = 10; // need to make it dynamic
// if the screen is not bigger than the target, then don't mess with zooming
if (currentWidth > targetWidth) {
if (typeof document.body.style.zoom != "undefined")
document.body.style.zoom = currentWidth / targetWidth;
else if (typeof document.body.style.MozTransform != "undefined") {
document.body.style.MozTransformOrigin = "left top";
document.body.style.MozTransform = 'scale(' + currentWidth / targetWidth + ')';
}
else if (typeof document.body.style.WebkitTransform != "undefined")
document.body.style.WebkitTransform = 'scale(' + currentWidth / targetWidth + ')';
$(document.body).width(targetWidth - scrollWidth);}})
这很好用,但如果身体小于1280像素,我无法弄清楚如何缩小它。 任何帮助将不胜感激。
答案 0 :(得分:0)
有几件事,jquery有两种我知道在文档就绪对象上触发的方法,一种是
$(document).ready(function(){
我熟悉的另一种速记是
$(function(){
建议不要使用$().ready
语法。请查看jquery文档http://api.jquery.com/ready/
此外,代码末尾没有结束分号。您可以在codeacademy上快速了解jquery语法。我发现如果一个jquery代码有错误的语法,DOM将不会完全加载。