ASP.NET利用XML實現旗幟廣告和Jquery製作旗幟廣告。

來源:互聯網
上載者:User

標籤:style   color   io   os   使用   java   ar   檔案   div   

一、編寫ad.xml,將其放入add_Data中(放在Add_Data中的理由:1.使該XML檔案在ASP.NET運行時自動獲得對其的讀取許可權。同時可以防止在瀏覽器中被查看):

<?xml version="1.0" encoding="utf-8"?>
<Advertisements>
<Ad>

<ImageUrl>要顯示圖片的連結</ImageUrl>

<NavigateUrl>點擊圖片是指向的網址</NavigateUrl>

<AlternateText>圖片不可用時顯示的文本</AlternateText>

<Impressions>指示廣告可能的頻率數值,數值越大,出現頻率越高</Impressions>

<Keyword>可用於篩選廣告的廣告類別</Keyword>

</Ad>
</Advertisements>

二、使用AdRotator控制項的AdvertisementFile屬性實現擷取XML路徑。關鍵代碼如下:

<asp:AdRotator ID="AdRitatir1" runat="server"

  AdvertisementFile="~/App_Data/ad.xml"

target="_blank"

OnAdCreated="AdCreated_Event"/>

使用這種方式相對於使用javascript來說要簡單方便的多。同時也能提高效率。

通過JS來控制CSS也能實現該效果,具體思路為:

1.把所有圖片都載入。設定圖片樣式overflow:hidden;position:relative;

通過JS來設定圖片樣式來達到滑動效果。以下為我當時學習Jquery的時候用過的一個案例:

index.html中廣告部分:

  <div class="ad" >
    <ul class="slider" >
    <li><img src="images/ads/1.gif"/></li>
    <li><img src="images/ads/2.gif"/></li>
    <li><img src="images/ads/3.gif"/></li>
    <li><img src="images/ads/4.gif"/></li>
    <li><img src="images/ads/5.gif"/></li>
     </ul>
     <ul class="num" >
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
     </ul>
  </div>

廣告部分樣式:

.content_right .ad {
 margin-bottom:10px;
 width:586px;
 height:150px;
 overflow:hidden;
 position:relative;
}
.content_right .slider,.content_right .num{
 position:absolute;
}
.content_right .slider li{
 list-style:none;
 display:inline;
}
.content_right .slider img{
 width:586px;
 height:150px;
 display:block;
}
.content_right .num{
 right:5px;
 bottom:5px;
}
.content_right .num li{
 float: left;
 color: #FF7300;
 text-align: center;
 line-height: 16px;
 width: 16px;
 height: 16px;
 font-family: Arial;
 font-size: 12px;
 cursor: pointer;
 overflow: hidden;
 margin: 3px 1px;
 border: 1px solid #FF7300;
 background-color: #fff;
}
.content_right .num li.on{
 color: #fff;
 line-height: 21px;
 width: 21px;
 height: 21px;
 font-size: 16px;
 margin: 0 1px;
 border: 0;
 background-color: #FF7300;
 font-weight: bold;
}

Jquery代碼:

$(function(){
     var len  = $(".num > li").length;
  var index = 0;
  var adTimer;
  $(".num li").mouseover(function(){
  index  =   $(".num li").index(this);
  showImg(index);
  }).eq(0).mouseover(); 
  //滑入 停止動畫,滑出開始動畫.
  $(‘.ad‘).hover(function(){
    clearInterval(adTimer);
   },function(){
    adTimer = setInterval(function(){
       showImg(index)
    index++;
    if(index==len){index=0;}
     } , 3000);
  }).trigger("mouseleave");
})
// 通過控制top ,來顯示不同的投影片
function showImg(index){
        var adHeight = $(".content_right .ad").height();
  $(".slider").stop(true,false).animate({top : -adHeight*index},1000);
  $(".num li").removeClass("on")
   .eq(index).addClass("on");
}

ASP.NET利用XML實現旗幟廣告和Jquery製作旗幟廣告。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.