css and javascript to show figcaption of image when clicked -
i having trouble configuring javascript css when image clicked little caption bar appear icons in it. when hover on image caption bar appears want change usable users on tablets have touch , don't have hover feature.
view page
<figure> <img width="158" height="158" alt="gravatar" data-bind="attr:{src: gravatarurl}" /> <figcaption> <a title="email" id="emailicon" class="icon-envelope icon-white" data-bind="attr:{'href':'mailto:' + email()}"></a> <a title="profile" id="profileicon" class="icon-user icon-white"></a> </figcaption> </figure>
css
figure, figcaption { display: block; } figure { position:relative; float:left; margin:20px; width:158px; height:158px; border:1px solid #333; overflow:hidden; background: #fff; padding: 1px; } figure figcaption { position:absolute; bottom:0; left:0; opacity: .75; margin-bottom:-115px; -webkit-transition: margin-bottom; -webkit-transition-duration: 400ms; -webkit-transition-timing-function: ease-out; -moz-transition-property: margin-bottom; -moz-transition-duration: 400ms; -moz-transition-timing-function: ease-out; -o-transition-property: margin-bottom; -o-transition-duration: 400ms; } figure.open figcaption { margin-bottom:0px; } figcaption { width:160px; height:25px; background:#111; color:#fff; font-family: arial, helvetica, sans-serif; }
javascript not sure if there way css or not.
<script type="text/javascript"> (function ($) { $.views.roster.getroster('@url'); $('figure').on('click', function (event) { $(event.currenttarget).toggleclass('open'); }); })(jquery); </script>
it's great idea toggle class , leave visible elements css.
$('figure').on('click', function (e) { $(this).toggleclass('open'); });
in case, style figcaption way want , add:
figcaption { display: none; } .open figcaption { display: block; }
this way, when figcaption hidden default when click target , javascript adds class "open" figcaption visible. don't have have display block, other "none."
Comments
Post a Comment