分类 Web前端 下的文章

禁止Html5页面在手机上屏幕页面缩放

最近测试html5页面,发现默认都允许用户缩放页面,或者在屏幕双击放大或缩小。即相当于这样设置

<meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=yes" />

如果要禁止此情形,修改相应参数即可。

<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;" name="viewport" />

阅读剩余部分

网页区块隐藏/显示的切换技术

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
</head>
<body>
    <style>
        .con {
            width: 960px;
            margin: 0 auto
        }
        .A,.B,.C {
            width: 400px;
            height: 200px;
            background: #F93;
            border-radius: 8px;
            padding: 50px;
        }
        .A {
            display: block
        }
        .B,.C {
            display: none
        }
        .a,.b,.c {
            float: left;
            width: 50px;
        }
    </style>
    <script type="text/javascript"> 
        $(function () { 
            $(".a").click(function () { 
                $(".A").show(); 
                $(".B").hide(); 
                $(".C").hide(); 
            })    
            $(".b").click(function () { 
                $(".B").show(); 
                $(".A").hide(); 
                $(".C").hide();
            }) 
            $(".c").click(function () { 
                $(".C").show(); 
                $(".B").hide(); 
                $(".A").hide(); 
            }) 
        })
    </script>
    <div class="con">
        <div class="A"><h1>循环A</h1></div>
        <div class="B"><h1> 循环B</h1></div>
        <div class="C"><h1>循环C</h1></div>
        <div class="a"><button>a</button></div>
        <div class="b"><button>b</button></div>
        <div class="c"><button>c</button></div>
    </div>
</body>
</html>

以上代码保存为html即可看到如下界面:

1.png

收藏这个代码主要原因是:原理一目了然,浅显易懂。引用jquery,然后js判断,当a被点击时,显示A,隐藏B,C;当b被点击时,显示B,隐藏A,C;当C被点击时,显示C,隐藏A,B。

若你想把点击效果改成悬停效果,那么就把以上js中的click都改成hover即可。

阅读剩余部分

一款简洁的html+js类焦点图(幻灯片)代码

这是公司前端发给我的,以后焦点图代码指定他了。

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style-type: none;
        }
        a img {
            border: 0;
        }
        .focus {
            width: 640px;
            height: 480px;
            position: relative;
            margin: 0 auto;
            overflow: hidden;
        }
        .focus ul {
            position: absolute;
        }
        .focus .pic li {
            width: 640px;
            height: 480px;
            overflow: hidden;
        }
        .focus div.btn {
            position: absolute;
            height: 18px;
            bottom: 10px;
            right: 0;
            text-align: right;
            font-family: Verdana;
            font-size: 10px;
            padding-right: 10px;
        }
        .focus div.btn span {
            display: inline-block;
            _display: inline;
            _zoom: 1;
            width: 18px;
            line-height: 18px;
            background: #333;
            color: #fff;
            cursor: pointer;
            text-align: center;
            margin-left: 5px;
        }
        .focus div.btn span.on {
            background: #f00;
        }
        .focus .txt {
            width: 100%;
            height: 40px;
            line-height: 40px;
            bottom: 0;
            overflow: hidden;
        }
        .focus .txt li {
            width: 100%;
            height: 100%;
            position: absolute;
        }
        .focus .txt li a {
            z-index: 1;
            color: #fff;
            position: relative;
            left: 10px;
        }
        .focus .txt li span {
            display: block;
            height: 100%;
            width: 100%;
            position: absolute;
            top: 0;
            left: 0;
            background: #333434;
            opacity: 0.5;
            filter: alpha(opacity=50);
        }
    </style>
    <script type="text/javascript" src="jquery-1.6.2.min.js"></script>
    <script type="text/javascript" src="focus.js"></script>
</head>
<body>
    <div id="focus" class="focus">
        <ul class="pic">
            <li><a href="#"><img src="10.jpg" alt="" /></a></li>
            <li><a href="#"><img src="11.jpg" alt="" /></a></li>
            <li><a href="#"><img src="12.jpg" alt="" /></a></li>
        </ul>
        <ul class="txt">
            <li><a href="#">文字介绍111</a><span></span></li>
            <li><a href="#">文字介绍222</a><span></span></li>
            <li><a href="#">文字介绍333</a><span></span></li>
        </ul>
    </div>
</body>
</html>

在下面下载完整版:

html+js类焦点图(幻灯片)代码.rar
016e50d69a5bc9ef21b8afa7190b983d.rar (188.57 KB)

阅读剩余部分