亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

ASP.NET jQuery 食譜20 (通過(guò)jQuery操作Image控

系統(tǒng) 1945 0

前言

這節(jié)我們來(lái)介紹ASP.NET里面的Image控件,和HTML的Image元素相比,它為開(kāi)發(fā)者提供了豐富的屬性和方法。除了使用這些方法屬性外,我們還可以通過(guò)jquery在客戶(hù)端為Image控件提供更多的功能。下面就開(kāi)始介紹各種通過(guò)jQuery操作Image控件的方法:

準(zhǔn)備工作

在樣式各種技巧前,先準(zhǔn)備頁(yè)面代碼如下:

      
        <
      
      
        form 
      
      
        id
      
      
        ="form1"
      
      
         runat
      
      
        ="server"
      
      
        >
      
      
< div align ="center" >
< fieldset style ="width: 470px; height: 340px;" >
< table border ="0" cellpadding ="3" cellspacing ="3" >
< tr >
< td >
< div class ="imgContainer" >
< asp:Image ID ="img2" runat ="server" ImageUrl ="~/images/image2.jpg" CssClass ="image"
ToolTip
="兩院風(fēng)景" />
< asp:Image ID ="img3" runat ="server" ImageUrl ="~/images/image3.jpg" CssClass ="image"
ToolTip
="兩院風(fēng)景" />
< asp:Image ID ="img4" runat ="server" ImageUrl ="~/images/image4.jpg" CssClass ="image"
ToolTip
="兩院風(fēng)景" />
< asp:Image ID ="img5" runat ="server" ImageUrl ="~/images/image5.jpg" CssClass ="image"
ToolTip
="兩院風(fēng)景" />
< asp:Image ID ="img1" runat ="server" ImageUrl ="~/images/image1.jpg" CssClass ="image"
ToolTip
="兩院風(fēng)景" /></ div >
</ td >
< td >
< asp:Image ID ="imgCrop" runat ="server" ImageUrl ="~/images/image5.jpg" CssClass ="image"
ToolTip
="兩院風(fēng)景2" />
</ td >
</ tr >
< tr >
< td >
< br />
< asp:Button ID ="btnAdd" runat ="server" Text ="添加圖片鏈接" /> &nbsp; < asp:Button ID ="btnRemove"
runat
="server" Text ="移除圖片鏈接" /> &nbsp; < asp:Button ID ="btnSwap" runat ="server" Text ="換一張圖片" /> &nbsp; < br />
< asp:Button ID ="btnPre" runat ="server" Text ="前一張" /> &nbsp; < asp:Button ID ="btnNext"
runat
="server" Text ="下一張" />
</ td >
< td >
< br />
< table border ="0" cellpadding ="2" cellspacing ="2" >
< tr >
< td >
X:
</ td >
< td >
< asp:TextBox ID ="txtX" runat ="server" Width ="25px" ></ asp:TextBox >
</ td >
< td >
Y:
</ td >
< td >
< asp:TextBox ID ="txtY" runat ="server" Width ="25px" ></ asp:TextBox >
</ td >
< td >
X2:
</ td >
< td >
< asp:TextBox ID ="txtX2" runat ="server" Width ="25px" ></ asp:TextBox >
</ td >
< td >
Y2:
</ td >
< td >
< asp:TextBox ID ="txtY2" runat ="server" Width ="25px" ></ asp:TextBox >
</ td >
< td >
Width:
</ td >
< td >
< asp:TextBox ID ="txtWidth" runat ="server" Width ="25px" ></ asp:TextBox >
</ td >
< td >
Height:
</ td >
< td >
< asp:TextBox ID ="txtHeight" runat ="server" Width ="25px" ></ asp:TextBox >
</ td >
</ tr >
</ table >
</ td >
</ tr >
</ table >
</ fieldset >
</ div >
</ form >

使用到的樣式:

      
        <
      
      
        style 
      
      
        type
      
      
        ="text/css"
      
      
        >
      
      
        
.imgContainer
{
position
: relative ;
width
: 400px ;
height
: 250px ;
}

.image
{
position
: absolute ;
top
: 0 ;
left
: 0 ;
width
: 400px ;
height
: 250px ;
}

.caption
{
font-family
: Arial ;
font-weight
: bold ;
position
: absolute ;
z-index
: 1000 ;
}
</ style >

界面效果:

ASP.NET jQuery 食譜20 (通過(guò)jQuery操作Image控件技巧集合)_第1張圖片

操作Image控件的各種技巧

? 實(shí)現(xiàn)給圖片添加和移除鏈接地址

              $(
      
        function
      
       () {
      
// wrap():在每個(gè)匹配的元素外層包上一個(gè)html元素
// unwrap():將匹配元素的父級(jí)元素刪除,保留自身(和兄弟元素,如果存在)在原來(lái)的位置
// 添加圖片鏈接
$("#<%=btnAdd.ClientID %>").click( function (e) {
e.preventDefault();
$("#<%=img1.ClientID %>").wrap('<a target="_blank"></a>');
$("#<%=btnRemove.ClientID %>").removeAttr("disabled");
$("#<%=btnAdd.ClientID %>").attr("disabled", "disabled");
});

// 移除圖片鏈接
$("#<%=btnRemove.ClientID %>").click( function (e) {
e.preventDefault();
$("#<%=img1.ClientID %>").unwrap();
$("#<%=btnRemove.ClientID %>").attr("disabled", "disabled");
$("#<%=btnAdd.ClientID %>").removeAttr("disabled");
});
});

? 實(shí)現(xiàn)鼠標(biāo)移動(dòng)到圖片上在圖片上顯示圖片說(shuō)明信息

              $(
      
        function
      
       () {
      
$("#form1 img").hover( function () {
// $(this).css("cursor", "pointer");
var caption = $( this ).attr("title");
$( this ).after("<div class='caption'>" + caption + "</div>");
}, function () {
$(".caption").remove();
});
});

? 實(shí)現(xiàn)鼠標(biāo)移動(dòng)到圖片上改變其透明度

              $(
      
        function
      
       () {
      
$("#img1").animate({ opacity: 0.8 }, 200);
$("#img1").hover( function () {
$( this ).animate({ opacity: 1.0 }, 200);
}, function () {
$( this ).animate({ opacity: 0.8 }, 200);
});
});

? 實(shí)現(xiàn)更換圖片的功能

              $(
      
        function
      
       () {
      
$("#btnSwap").removeAttr("disabled");
$("#btnSwap").click( function (e) {
e.preventDefault();
$("#img1").attr("src", "../images/image2.jpg");
$( this ).attr("disabled", "disabled");
});
});

? 實(shí)現(xiàn)圖片的剪切功能

          <link type="text/css" rel="Stylesheet" href="../Styles/Jcrop/jquery.Jcrop.css" />
      
<script type="text/javascript" src="../Scripts/jquery.js"></script>
<script type="text/javascript" src="../Scripts/jquery.Jcrop.min.js"></script>
// 插件Jcrop下載地址:http://deepliquid.com/content/Jcrop.html
$( function () {
$("#imgCrop").Jcrop({
onChange: showCoords,
onSelect: showCoords
});

function showCoords(e) {
// 顯示剪切區(qū)域左上角點(diǎn)坐標(biāo)
$("#txtX").val(e.x);
$("#txtY").val(e.y);
// 顯示剪切區(qū)域右下角點(diǎn)坐標(biāo)
$("#txtX2").val(e.x2);
$("#txtY2").val(e.y2);
// 顯示剪切區(qū)域長(zhǎng)和寬
$("#txtWidth").val(e.w);
$("#txtHeight").val(e.h);
}
});

? 實(shí)現(xiàn)鼠標(biāo)移動(dòng)到圖片上放大圖片

              $(
      
        function
      
       () {
      
var zoom = 1.1; // 定義圖片放大的倍數(shù)
var move = -20; // 放大圖片后左上角偏移的距離

$("#img1").hover( function () {
var imgWidth = parseInt($( this ).width()) * zoom;
var imgHeight = parseInt($( this ).height()) * zoom;
$( this ).animate({ 'width': imgWidth,
'height': imgHeight,
'top': move,
'left': move
}, { duration: 200 });
}, function () {
$( this ).animate({ 'width': $(".imgContainer").width(),
'height': $(".imgContainer").height(),
'top': '0',
'left': '0'
}, 100);
});
});

? 實(shí)現(xiàn)圖片輪流切換

      
        //
      
      
         實(shí)現(xiàn)原理:通過(guò)z-index樣式屬性實(shí)現(xiàn)圖片切換的效果
      
      
        
$( function () {
var z = 0;
var max_z = $(".imgContainer img").length;
$(".imgContainer img").each( function () {
z++;
$( this ).css("z-index", z);
});

$("#btnPre").bind("click", function (e) {
e.preventDefault();
$(".imgContainer img").each( function () {
var cur_z_index = parseInt($( this ).css("z-index"));
if (cur_z_index == 1) {
$( this ).css("z-index", max_z);
}
else {
$( this ).css("z-index", (cur_z_index - 1));
}
});
});

$("#btnNext").bind("click", function (e) {
e.preventDefault();
$(".imgContainer img").each( function () {
var cur_z_index = parseInt($( this ).css("z-index"));
if (cur_z_index == max_z) {
$( this ).css("z-index", 1);
}
else {
$( this ).css("z-index", (cur_z_index + 1));
}
});
});
});

? 實(shí)現(xiàn)簡(jiǎn)單圖片相冊(cè)

我們?cè)诤芏鄨D片展示的網(wǎng)上,會(huì)用到圖片相冊(cè)的功能,通過(guò)點(diǎn)擊縮略圖顯示對(duì)應(yīng)的大圖片的功能,下面來(lái)看下如何簡(jiǎn)單的實(shí)現(xiàn)這個(gè)效果。

首先需要準(zhǔn)備頁(yè)面代碼:

      
        <
      
      
        form 
      
      
        id
      
      
        ="form1"
      
      
         runat
      
      
        ="server"
      
      
        >
      
      
< div align ="center" >
< fieldset style ="width: 600px; height: 390px;" >
< table border ="0" cellpadding ="3" cellspacing ="3" >
< tr >
< td >
< table border ="0" cellpadding ="2" cellspacing ="2" >
< tr >
< td >
< asp:Image ID ="image1" ImageUrl ="~/images/image1.jpg" runat ="server" CssClass ="thumbnail" />
</ td >
< td >
< asp:Image ID ="image2" ImageUrl ="~/images/image2.jpg" runat ="server" CssClass ="thumbnail" />
</ td >
< td >
< asp:Image ID ="image3" ImageUrl ="~/images/image3.jpg" runat ="server" CssClass ="thumbnail" />
</ td >
< td >
< asp:Image ID ="image4" ImageUrl ="~/images/image4.jpg" runat ="server" CssClass ="thumbnail" />
</ td >
< td >
< asp:Image ID ="image5" ImageUrl ="~/images/image5.jpg" runat ="server" CssClass ="thumbnail" />
</ td >
</ tr >
</ table >
</ td >
</ tr >
< tr >
< td align ="center" >
< div id ="imgContainer" >
</ div >
</ td >
</ tr >
</ table >
</ fieldset >
</ div >
</ form >

使用的樣式代碼:

      
        <
      
      
        style 
      
      
        type
      
      
        ="text/css"
      
      
        >
      
      
        
.thumbnail
{
position
: relative ;
width
: 100px ;
height
: 68px ;
}

.image
{
position
: relative ;
width
: 400px ;
height
: 250px ;
}
</ style >

腳本代碼:

      
        <
      
      
        script 
      
      
        type
      
      
        ="text/javascript"
      
      
        >
      
      
        
// 實(shí)現(xiàn)鼠標(biāo)移動(dòng)到縮略圖上顯示對(duì)應(yīng)的大圖
$( function () {
$(
" .thumbnail " ).hover( function () {
$(
" .thumbnail " ).css( " opacity " , " 0.5 " );
$(
this ).animate({ opacity: 1.0 }, 200 );
$(
" #imgContainer " ).append( " <img class='image' src=' " + $( this ).attr( " src " ) + " '/> " );
},
function () {
$(
" .thumbnail " ).css( " opacity " , " 1.0 " );
$(
" .image " ).remove();
});
});
</ script >

最終效果:

ASP.NET jQuery 食譜20 (通過(guò)jQuery操作Image控件技巧集合)_第2張圖片

這些技巧雖然很基礎(chǔ),通過(guò)學(xué)會(huì)使用這些技巧后,相信你以后在實(shí)現(xiàn)更復(fù)雜的圖片展示效果時(shí),會(huì)更加輕松容易。

ASP.NET jQuery 食譜20 (通過(guò)jQuery操作Image控件技巧集合)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 亚洲国产品综合人成综合网站 | 国产午夜精品福利 | 久久久久亚洲精品一区二区三区 | 五月婷婷丁香在线视频 | 成人精品国产亚洲欧洲 | 国产一区二区三区免费在线视频 | 欧美另类成人 | 国产一级α片 | 欧日韩在线不卡视频 | 综合网色 | 欧美久久久久久久一区二区三区 | 这里只有精品免费视频 | 精品一区二区久久 | 欧美a视频在线观看 | 天天插日日射 | 国产香蕉一区二区在线网站 | 国产精品天干天干 | 国产成人精品本亚洲 | 国产精品福利视频免费观看 | 国产亚洲精品yxsp | 99国产成人高清在线视频 | 亚洲春色综合另类网蜜桃 | 久久久婷婷亚洲5月97色 | 特级毛片| x99av在线播放 | 99久久国内精品成人免费 | 欧美成人午夜影院 | 亚洲国产一区二区a毛片日本 | 九九九网站| 色猫咪av在线网址 | 国产一级高清 | 激情奇米 | 99精品视频在线在线视频观看 | 青娱乐伊人 | 久久99精品久久久久久国产人妖 | 久久亚洲网站 | 伊人天天干| 国产中文字幕视频在线观看 | 99热亚洲 | 一级黄色录像毛片 | 毛片免费看看 |