Blogger Information
Blog 61
fans 0
comment 0
visits 63215
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jQuery设置内联样式
Pengsir
Original
2024 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jQuery设置内联样式</title>
    <style>
        .box1{
            width: 500px;
            height: 500px;
            border-radius: 20%;
            background-color: paleturquoise;
            position: relative;
        }
        .box2{
            width: 200px;
            height: 200px;
            background-color: red;
            top:100px;
            left: 150px;
            position: absolute;
        }
    </style>
</head>
<body>
<img src="img9.jpg" alt="">
    <div class="box1">
        <div class="box2"></div>
    </div>
</body>
<script src="../jquery/jquery-3.2.1.min.js"></script>
<script>
    var pic=$('img').css('width','200px')
    var pic=$('img').css('width','200px').css('border-radius','50%').css('box-shadow','2px 2px 2px #888')
    var pic = parseInt($('img').css('width'))
        pic+=100
    var pic=$('img').css('width',pic+'px')
//    var pic=$('img').css('width')
//    获取图片的宽度
    var pic=$('img').width()
    var pic=$('img').height()
    var pic=parseInt($('img').css('height'))
    pic+=500
    var pic=$('img').css('height',pic+'px')
//    获取图片的高度
    var pic=$('img').height()
//    获取图片在文档里的偏移量
    var pic=$('img').offset()
//        获取.box2的位置
    var pic=$('.box2').position()
    console.log(pic)
</script>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

总结:

  1. 设置内联样式   $('img').css('width','200px')

  2. 获取图片宽度快捷方式  $('img').width

  3. 获取图片高度快捷方式  $('img').height

  4. 获取图片偏移量 $('img').offset()

  5. 获取块.box2的位置 $('.box2').position()

手抄:

IMG_2581.JPGIMG_2582.JPG

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post