失礼します。
現在ブログの記事が今日の日付だった場合に、
その記事に「NEW」の画像を表示する機能を付ける
作業を行なっています。
調べながらやっては見たのですが、
動かず、行き詰まってしまいました。
大変申し訳ないのですが、
詳しい方にアドバイスをいただきたいです。
htmlの
class="time"の日付が今日の時のみ
span class="new"の画像を表示させたいです。
宜しくお願い致します。
【LD】 <IndexArticlesLoop> <li class="time_wrap"> <div class="news_img"> <!--記事の見出し--> <div class="image2"> <a href="<$ArticlePermalink$>" itemprop="url"><img src="<$ArticleCoverImage$>" /> </div> </div> <!--記事タイトル--> <div class="news_p"> <p><$ArticleTitle ESCAPE$></p></a> </div> <!--更新日--> <span class="new"><!--new--> <img src= alt=""> </span><!--/new--> <p class="time"> <$ArticleDateYear$>.<$ArticleDateMonth$>.<$ArticleDateDay$> </p> <!--カテゴリー--> <a href="<$ArticleCategory2Url$>"><span class="right"><$ArticleCategory2$></span></a> <a href="<$ArticleCategory1Url$>"><span class="right"><$ArticleCategory1$></span></a> </li> </IndexArticlesLoop> </div>
【CSS】 .news .whats_all { margin: 39px 0 36px 3%; } .whats_all img { width: 213px; margin-top: 10px; } .date_display { position: absolute; top: 52px; left: 594px; color: #d9ebf5; z-index: -1; font-family: "Futura",serif; } .date_display li { float: left; } li p.update { margin-top: -1px; margin-right: -5px; line-height: 1.5em; font-size: 25.02px; font-weight: 200; } li p.month { margin-top: 4px; margin-left: 12px; font-size: 27.48px;; font-weight: 600; } li p.slash { margin-top: -15px; margin-right: 7px; margin-left: -20px; } li p.date { margin-top: -16px; margin-left: -18px; font-size: 93px; font-weight: 300; letter-spacing: -6px; } .news { width: 900px; margin-left: -27px; float: left; position: relative; } .news a { text-decoration: none; color: #000; } .news_img { max-width: 261px; max-height: 146.55px; min-width: 261px; min-height: 146.55px; overflow: hidden; } .image2{ position: relative; width: 100%; padding-top: 75%; overflow: hidden; margin: 0 auto; } .image2 img{ position: absolute; top: 38%; left: 50%; -webkit-transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); max-width: 150%; max-height: 150%; } .news .text li { width: 261px; min-height: 284px; max-height: 284px; float: left; border-bottom: solid 1px #e5e5e5; padding-bottom: 4px; margin-bottom: 41px; margin-left: 3%; text-decoration: none; list-style:none; } .news_p { height: 65px; overflow: hidden; } .news .text p { margin-top: 15px; line-height: 1.5em; font-size: 14px; } .time_wrap span.new{ display: none; float: left; margin: 16px 10px 4px 0; width: 47px; } .news p.time { float: left; margin: 19px 0px 25px 0; color: #555555; font-size: 14px; } .news .right { float: right; margin: 24px 0 25px 0; color: #999999; font-size: 12px; }
【js】 <script type="text/javascript"> $(function(){ // 今日の日付情報を取得し変数dTodayに格納する var now = new Date(); var yyyymmdd = now.getFullYear()+ ( "0"+( now.getMonth()+1 ) ).slice(-2)+ ( "0"+now.getDate() ).slice(-2); $('.time_wrap').each(function(){ var news_time = $(this).find(".time").text(); str_first = news_time.substring(0, 4); str_mdl = news_time.substring(5, 6); str_btm = news_time.substring(7, 9); news_time02 = str_first + "0" +str_mdl + str_btm; if (yyyymmdd == news_time02 ) { $(this).find("span").css('display','block'); } else { } }); }); </script>
htmlをブラウザで表示したものになります。
絶対パスに関しては、一部省略しております。
<li class="time_wrap"> <div class="news_img"> <!--記事の見出し--> <div class="image2"> <a href="http://blog.livedoor.jp/" itemprop="url"><img src="http://livedoor.blogimg.jp/ > </div> </div> <!--記事タイトル--> <div class="news_p"> <p>test</p></a> </div> <!--更新日--> <span class="new"><!--new--> <img src="http://blog.livedoor.jp/> </span><!--/new--> <p class="time"> 2017.9.29 </p> <!--カテゴリー--> <a href=""><span class="right"></span></a> <a href=""><span class="right"></span></a> </li> </script>
回答1件
あなたの回答
tips
プレビュー