2014-10-28 208 views
1

我正在爲一個學校項目創建一個網站,我們被要求選擇一家公司爲其設計一個模擬宣傳網站。我選擇了CVS,但你可以選擇任何人。我設法使用了一個我已經完成了一些codecamdemy類的模板,但是這些教程在改變圖像長度方面似乎沒有幫助。我想要做的是在整個幻燈片容器的整個長度上擴展名爲「nyse」,「導師」和「山」的圖像,但到目前爲止,當我改變它時,圖像似乎沒有做任何事情。任何人都可以告訴我它在哪裏出錯或在哪裏放置我的代碼來擴展圖像?我已經嘗試了很多div,但迄今爲止沒有運氣。我的代碼如下。在幻燈片上擴展圖像活動幻燈片

HTML

<!doctype html> 
<html> 
    <head> 
    <link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet'> 
    <link href="http://s3.amazonaws.com/codecademy-content/courses/ltp2/css/bootstrap.min.css" rel="stylesheet"> 
    <link href="style.css" rel="stylesheet"> 
    </head> 
    <body> 
    <div class="header"> 
     <div class="container"> 
     <a href="#" class="logo-icon"> 
      <img src="img/cvs.png"> 
     </a> 

     <div class="headerNi"> 
     <div class="container"> 
     <a href="#" class="logo-icon"> 
      <p><a href title="Click this link to view the scheme.">NIDC Graduate Scheme</a></p> 
     </a> 
     <div id ="headerMission">CVS Health's Northern Ireland Development Centre, which opened in 2012,<br> 
creates software solutions for all parts of the US company,<br> 
with particular focus on internet and mobile applications.</div></div> 


     <ul class="menu"> 
      <li><a href="#">Home</a></li> 
      <li><a href="#">About Us</a></li> 
      <li><a href="#">Curriculum</a></li> 
      <li><a href="#">Staff Profiles</a></li> 
      <li><a href="#">Careers</a></li> 
      <li><a href="#">Register</a></li> 
      <li class="dropdown"> 
      <a href="#" class="dropdown-toggle">More <b class="caret"></b></a> 
      <ul class="dropdown-menu"> 
       <li><a href="#">Graduate Scheme</a></li> 
       <li><a href="#">What we look for</a></li> 
       <li><a href="#">Links</a></li> 
      </ul> 
      </li> 
     </ul> 
     </div> 
    </div> 
    </div> 
    </div> 

    <div class="slider"> 

     <div id="nyse-slide" class="slide"> 
     <div class="container"> 
      <div class="row"> 
      <div class="slide-copy col-xs-5"> 
       <h1>CVS is now hiring</h1> 
       <p>We will soon have a nice new building.</p> 

       <ul class="get-app"> 
       <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/ios.png"></a></li> 
       <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/android.png"></a></li> 
       <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/windows.png"></a></li> 
       <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/blackberry.png"></a></li> 
       </ul> 
      </div> 
      <div class="slide-img col-xs-7"> 
       <img src="img/nyse.jpg" width="540px"> 
      </div> 
      </div> 
     </div>  
     </div> 

     <div class="slide slide-feature"> 
     <div class="container"> 
      <div class="row"> 
      <div class="col-xs-12"> 
      <br></br> 
       <br></br> 
        <br></br> 
        <br></br> 
         <br></br> 
         <br></br> 
          <br></br> 
       <a href="#">Accountability</a> 
       <p>Take responsibility for your actions.</p> 
      </div> 

      </div> 
     </div>  
     </div> 

     <div id="mountain-slide" class="slide"> 
     <div class="container"> 
      <div class="row"> 
      <div class="slide-copy col-xs-5"> 
       <h1>Collaboration</h1> 
       <p>At CVS, it's important to work together with your mentor!</p> 

      </div> 
      <div class="slide-img col-xs-7"> 
       <img src="img/mountain.png"> 
      </div> 
      </div> 
     </div>  
     </div> 


     <div id="pharm-slide" class="slide"> 
     <div class="container"> 
      <div class="row"> 
      <div class="slide-copy col-xs-5"> 
       <h1>Tenacity</h1> 
       <p>Be determined.</p> 

       <ul class="get-app"> 
       <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/ios.png"></a></li> 
       <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/android.png"></a></li> 
       <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/windows.png"></a></li> 
       <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/blackberry.png"></a></li> 
       </ul> 
      </div> 
      <div class="slide-img col-xs-7"> 
       <img src="img/pharm.jpg" width="540px"> 
      </div> 
      </div> 
     </div>  
     </div> 

    </div> 

    <div class="slider-nav"> 
     <a href="#" class="arrow-prev"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/arrow-prev.png"></a> 
     <ul class="slider-dots"> 
     <li class="dot active-dot">&bull;</li> 
     <li class="dot">&bull;</li> 
     <li class="dot">&bull;</li> 
     <li class="dot">&bull;</li> 
     </ul> 
     <a href="#" class="arrow-next"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/arrow-next.png"></a> 
    </div> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
    <script src="app.js"></script> 
    </body> 
</html> 

CSS

.container { 
    width: 960px; 
    color: gray; 
} 

/* Header */ 

.header { 
    background-color: rgba(255, 255, 255, 0.95); 
    border-bottom: 1px solid #ddd; 

    font-family: 'Oswald', sans-serif; 
    font-weight: 300; 

    font-size: 17px; 
    padding: 15px; 
} 


/* Menu */ 

.header .menu { 
    float: right; 
    list-style: none; 
    margin-top: 5px; 
} 

.menu > li { 
    display: inline; 
    padding-left: 20px; 
    padding-right: 20px; 
} 

.menu a { 
    color: #898989; 
} 

/* Dropdown */ 

.dropdown-menu { 
    font-size: 16px; 
    margin-top: 5px; 
    min-width: 105px; 
} 

.dropdown-menu li a { 
    color: #898989; 
    padding: 6px 20px; 
    font-weight: 300; 
} 


/* Carousel */ 

.slider { 
    position: relative; 
    width: 100%; 
    height: 470px; 
    border-bottom: 1px solid #ddd; 
} 

.slide { 
    background: transparent url('http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/feature-gradient-transparent.png') center center no-repeat; 
    background-size: cover; 
    display: none; 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
} 
    .slide { 
      text-align: center; 
      height: 550px; 
     } 

     #nyce-slide{ 
      background-image: url('nsce.jpg'); 
     } 
     #pharm-slide-feature{ 
      background-image: url('pharm.jpg'); 
     } 
     #mountain-slide-feature{ 
      background-image: url('mountain.jpg'); 
     } 
.active-slide { 
    display: block; 
} 

.slide-copy h1 { 
    color: #363636; 

    font-family: 'Oswald', sans-serif; 
    font-weight: 400; 

    font-size: 40px; 
    margin-top: 105px; 
    margin-bottom: 0px; 
} 

.slide-copy h2 { 
    color: #b7b7b7; 

    font-family: 'Oswald', sans-serif; 
    font-weight: 400; 

    font-size: 40px; 
    margin: 5px; 
} 

.slide-copy p { 
    color: #959595; 
    font-family: Georgia, "Times New Roman", serif; 
    font-size: 1.15em; 
    line-height: 1.75em; 
    margin-bottom: 15px; 
    margin-top: 16px; 
} 

.slide-img { 
    text-align: right; 
} 

/* Slide feature */ 

.slide-feature { 
    text-align: center; 
    background-image: url('http://devonsstudio.com/businesspeople.png'); 
    height: 550px; 
} 

.slide-feature img { 
    margin-top: 112px; 
    margin-bottom: 28px; 
} 

.slide-feature a { 
    display: block; 
    color: #6fc5e0; 

    font-family: "HelveticaNeueMdCn", Helvetica, sans-serif; 
    font-family: 'Oswald', sans-serif; 
    font-weight: 400; 

    font-size: 20px; 
} 
.slide-feature p { 
color: red; 
} 

.slider-nav { 
    text-align: center; 
    margin-top: 80px; 

} 

.arrow-prev { 
    margin-right: 45px; 
    display: inline-block; 
    vertical-align: top; 
    margin-top: 9px; 
} 

.arrow-next { 
    margin-left: 45px; 
    display: inline-block; 
    vertical-align: top; 
    margin-top: 9px; 
} 

.slider-dots { 
    list-style: none; 
    display: inline-block; 
    padding-left: 0; 
    margin-bottom: 0; 
} 

.slider-dots li { 
    color: #bbbcbc; 
    display: inline; 
    font-size: 30px; 
    margin-right: 5px; 
} 

.slider-dots li.active-dot { 
    color: #363636; 
} 

/* App links */ 

.get-app { 
    list-style: none; 
    padding-bottom: 9px; 
    padding-left: 0px; 
    padding-top: 9px; 
} 

.get-app li { 
    float: left; 
    margin-bottom: 5px; 
    margin-right: 5px; 
} 

.get-app img { 
    height: 40px; 
} 
     color: #898989; 
     padding: 6px 20px; 
     font-weight: 300; 
    } 


    /* Carousel */ 

    .slider { 
     position: relative; 
     width: 100%; 
     height: 470px; 
     border-bottom: 1px solid #ddd; 
    } 

    .slide { 
     background: transparent url('http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/feature-gradient-transparent.png') center center no-repeat; 
     background-size: cover; 
     display: none; 
     position: absolute; 
     top: 0; 
     left: 0; 
     width: 100%; 
     height: 100%; 
    } 

    .active-slide { 
     display: block; 
    } 

    .slide-copy h1 { 
     color: #363636; 

     font-family: 'Oswald', sans-serif; 
     font-weight: 400; 

     font-size: 40px; 
     margin-top: 105px; 
     margin-bottom: 0px; 
    } 

    .slide-copy h2 { 
     color: #b7b7b7; 

     font-family: 'Oswald', sans-serif; 
     font-weight: 400; 

     font-size: 40px; 
     margin: 5px; 
    } 

    .slide-copy p { 
     color: #959595; 
     font-family: Georgia, "Times New Roman", serif; 
     font-size: 1.15em; 
     line-height: 1.75em; 
     margin-bottom: 15px; 
     margin-top: 16px; 
    } 

    .slide-img { 
     text-align: right; 
    } 

    /* Slide feature */ 

    .slide-feature { 
     text-align: center; 
     background-image: url('http://devonsstudio.com/businesspeople.png'); 
     height: 550px; 
    } 

    .slide-feature img { 
     margin-top: 112px; 
     margin-bottom: 28px; 
    } 

    .slide-feature a { 
     display: block; 
     color: #6fc5e0; 

     font-family: "HelveticaNeueMdCn", Helvetica, sans-serif; 
     font-family: 'Oswald', sans-serif; 
     font-weight: 400; 

     font-size: 20px; 
    } 
    .slide-feature p { 
    color: red; 
    } 

    .slider-nav { 
     text-align: center; 
     margin-top: 80px; 

    } 

    .arrow-prev { 
     margin-right: 45px; 
     display: inline-block; 
     vertical-align: top; 
     margin-top: 9px; 
    } 

    .arrow-next { 
     margin-left: 45px; 
     display: inline-block; 
     vertical-align: top; 
     margin-top: 9px; 
    } 

    .slider-dots { 
     list-style: none; 
     display: inline-block; 
     padding-left: 0; 
     margin-bottom: 0; 
    } 

    .slider-dots li { 
     color: #bbbcbc; 
     display: inline; 
     font-size: 30px; 
     margin-right: 5px; 
    } 

    .slider-dots li.active-dot { 
     color: #363636; 
    } 

    /* App links */ 

    .get-app { 
     list-style: none; 
     padding-bottom: 9px; 
     padding-left: 0px; 
     padding-top: 9px; 
    } 

    .get-app li { 
     float: left; 
     margin-bottom: 5px; 
     margin-right: 5px; 
    } 

    .get-app img { 
     height: 40px; 
    } 

JAVASCRIPT

var main = function() { 
    $('.dropdown-toggle').click(function() { 
    $('.dropdown-menu').toggle(); 
    }); 


    $('.arrow-next').click(function(e) { 
     e.preventDefault(); 
    var currentSlide = $('.active-slide'); 
    var nextSlide = currentSlide.next(); 

    var currentDot = $('.active-dot'); 
    var nextDot = currentDot.next(); 

    if(nextSlide.length === 0) { 
     nextSlide = $('.slide').first(); 
     nextDot = $('.dot').first(); 
    } 

    currentSlide.fadeOut(600).removeClass('active-slide'); 
    nextSlide.fadeIn(600).addClass('active-slide'); 

    currentDot.removeClass('active-dot'); 
    nextDot.addClass('active-dot'); 
    }); 


    $('.arrow-prev').click(function(e) { 
     e.preventDefault(); 
    var currentSlide = $('.active-slide'); 
    var prevSlide = currentSlide.prev(); 

    var currentDot = $('.active-dot'); 
    var prevDot = currentDot.prev(); 

    if(prevSlide.length === 0) { 
     prevSlide = $('.slide').last(); 
     prevDot = $('.dot').last(); 
    } 

    currentSlide.fadeOut(600).removeClass('active-slide'); 
    prevSlide.fadeIn(600).addClass('active-slide'); 

    currentDot.removeClass('active-dot'); 
    prevDot.addClass('active-dot'); 
    }); 

} 

$(document).ready(main); 
+0

當你說「擴展圖像的整個容器的寬度」?你到底什麼意思?當您點擊$('。arrow-next')鏈接時,您希望它如何操作? – CodeGodie 2014-10-28 13:38:42

+0

您是否看到問責性部分中的圖像如何擴展導航滑塊的整個大小?我基本上想要擴展其他圖像來做同樣的事情。 – Rory 2014-10-28 13:48:47

+0

好吧,我更新了我的答案。請檢查一下。 – CodeGodie 2014-10-28 14:11:43

回答

1

繼承人DEMO FIDDLE(你只需要網址添加您的圖像到CSS)

您需要做的第一件事是添加e.preventDefault();在點擊evennts這樣的:

$('.arrow-next').click(function(e) { 
     e.preventDefault(); 
     //..more code 
}); 

$('.arrow-prev').click(function(e) { 
     e.preventDefault(); 
     //..more code 
}); 

然後,你需要給每個幻燈片一個唯一的ID,並給它的圖像背景,就像你有這樣的.slide特徵背景:

HTML:

<div id="nyce-slide" class="slide"> 
    <!-- ...code.. --> 
</div> 

<div id="mountain-slide" class="slide"> 
    <!-- ...code.. --> 
</div> 

<div id="mentor-slide" class="slide"> 
    <!-- ...code.. --> 
</div> 

CSS:

 .slide { 
      text-align: center; 
      height: 550px; 
     } 

     #nyce-slide{ 
      background-image: url('nyce.jpg'); 
     } 
     #mentor-slide{ 
      background-image: url('mentor.jpg'); 
     } 
     #mountain-slide{ 
      background-image: url('mountain.jpg'); 
     } 

繼承人的最終編輯:

<body> 
    <div class="header"> 
     <div class="container"> 
      <a href="#" class="logo-icon"> 
       <img src="img/cvs.png"> 
      </a> 

      <div class="headerNi"> 
       <div class="container"> 
        <a href="#" class="logo-icon"> 
         <p><a href title="Click this link to view the scheme.">NIDC Graduate Scheme</a></p> 
        </a> 
        <div id ="headerMission">CVS Health's Northern Ireland Development Centre, which opened in 2012,<br> 
         creates software solutions for all parts of the US company,<br> 
         with particular focus on internet and mobile applications.</div></div> 


       <ul class="menu"> 
        <li><a href="#">Home</a></li> 
        <li><a href="#">About Us</a></li> 
        <li><a href="#">Curriculum</a></li> 
        <li><a href="#">Staff Profiles</a></li> 
        <li><a href="#">Careers</a></li> 
        <li><a href="#">Register</a></li> 
        <li class="dropdown"> 
         <a href="#" class="dropdown-toggle">More <b class="caret"></b></a> 
         <ul class="dropdown-menu"> 
          <li><a href="#">Graduate Scheme</a></li> 
          <li><a href="#">What we look for</a></li> 
          <li><a href="#">Links</a></li> 
         </ul> 
        </li> 
       </ul> 
      </div> 
     </div> 
    </div> 

    <div class="slider"> 

     <div id="nyce-slide" class="slide active-slide"> 
      <div class="container"> 
       <div class="row"> 
        <div class="slide-copy col-xs-5"> 
         <h1>CVS is now hiring</h1> 
         <p>We will soon have a nice new building.</p> 

         <ul class="get-app"> 
          <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/ios.png"></a></li> 
          <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/android.png"></a></li> 
          <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/windows.png"></a></li> 
          <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/blackberry.png"></a></li> 
         </ul> 
        </div> 
       </div> 
      </div>  
     </div> 

     <div id="accountability-slide" class="slide"> 
      <div class="container"> 
       <div class="row"> 
        <div class="col-xs-12"> 
         <br></br> 
         <br></br> 
         <br></br> 
         <br></br> 
         <br></br> 
         <br></br> 
         <br></br> 
         <a href="#">Accountability</a> 
         <p>Take responsibility for your actions.</p> 
        </div> 

       </div> 
      </div>  
     </div> 

     <div id="mountain-slide" class="slide"> 
      <div class="container"> 
       <div class="row"> 
        <div class="slide-copy col-xs-5"> 
         <h1>Collaboration</h1> 
         <p>At CVS, it's important to work together with your mentor!</p> 

        </div> 
       </div> 
      </div>  
     </div> 


     <div id="mentor-slide" class="slide"> 
      <div class="container"> 
       <div class="row"> 
        <div class="slide-copy col-xs-5"> 
         <h1>Tenacity</h1> 
         <p>Be determined.</p> 

         <ul class="get-app"> 
          <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/ios.png"></a></li> 
          <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/android.png"></a></li> 
          <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/windows.png"></a></li> 
          <li><a href="#"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/blackberry.png"></a></li> 
         </ul> 
        </div> 
       </div> 
      </div>  
     </div> 

    </div> 

    <div class="slider-nav"> 
     <a href="#" class="arrow-prev"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/arrow-prev.png"></a> 
     <ul class="slider-dots"> 
      <li class="dot active-dot">&bull;</li> 
      <li class="dot">&bull;</li> 
      <li class="dot">&bull;</li> 
      <li class="dot">&bull;</li> 
     </ul> 
     <a href="#" class="arrow-next"><img src="http://s3.amazonaws.com/codecademy-content/courses/ltp2/img/flipboard/arrow-next.png"></a> 
    </div> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
    <script> 
     var main = function() { 
      $('.dropdown-toggle').click(function() { 
       $('.dropdown-menu').toggle(); 
      }); 


      $('.arrow-next').click(function(e) { 
       e.preventDefault(); 
       var currentSlide = $('.active-slide'); 
       var nextSlide = currentSlide.next(); 

       var currentDot = $('.active-dot'); 
       var nextDot = currentDot.next(); 

       if (nextSlide.length === 0) { 
        nextSlide = $('.slide').first(); 
        nextDot = $('.dot').first(); 
       } 

       currentSlide.fadeOut(600).removeClass('active-slide'); 
       nextSlide.fadeIn(600).addClass('active-slide'); 

       currentDot.removeClass('active-dot'); 
       nextDot.addClass('active-dot'); 
      }); 


      $('.arrow-prev').click(function(e) { 
       e.preventDefault(); 
       var currentSlide = $('.active-slide'); 
       var prevSlide = currentSlide.prev(); 

       var currentDot = $('.active-dot'); 
       var prevDot = currentDot.prev(); 

       if (prevSlide.length === 0) { 
        prevSlide = $('.slide').last(); 
        prevDot = $('.dot').last(); 
       } 

       currentSlide.fadeOut(600).removeClass('active-slide'); 
       prevSlide.fadeIn(600).addClass('active-slide'); 

       currentDot.removeClass('active-dot'); 
       prevDot.addClass('active-dot'); 
      }); 

     } 

     $(document).ready(main); 
    </script> 
</body> 
+0

我已經插入了您的建議,但仍然無法正常工作。演示提琴不顯示圖片。如果我在添加了您的建議的地方編輯我的代碼,您是否可以告訴我我要出錯的地方? – Rory 2014-10-28 14:20:37

+1

演示不會顯示您的圖像,因爲我不知道您使用的是什麼圖像。您必須將圖片的網址放入CSS部分。是的,你可以繼續發佈你迄今爲止已經更新的內容,並且生病看看它。當它更新時讓我知道。 – CodeGodie 2014-10-28 14:24:17

+0

我使用的圖像只是我存儲在筆記本電腦上的jpgs。但是如果你需要爲自己看點什麼,你可以使用任何東西作爲替代品。我現在更新了代碼,我認爲你的建議應該去 - 他們是否在正確的位置? – Rory 2014-10-28 14:33:19