Learning
Learning

Reputation: 20001

jQuery Mobile listview descrption with scrolling

I have a listview with some long title which automatically is hidden on small screen display and post fixed with ...

I am not sure if it is possible to make these long title of descriptions to scroll if whole title doesnt show up on the screen.

Example on jsFiddle

<div data-role="page" id="MessagesPage">
    <div data-role="header">
        <a href="#HomePage" data-icon="home" data-direction="reverse">Home</a>      
        <h1 id="ScheduleDayText">Messages</h1>
    </div>
    <div data-role="content">   
        <ul data-role="listview" id="MessagesList" data-autodividers="false">
            <li date="2013-03-20"><a href="#">Event 1 With take every second Saturday of each month</a></li>
            <li date="2013-03-20"><a href="#">Event 2 With take every second Thrusday of each month</a></li>
            <li date="2013-03-19"><a href="#">Event 3</a></li>
       </ul>
    </div>
</div>

Can we make title to scroll to left or right on mouse hover so that user can read the title before they click on the link or button.

Upvotes: 2

Views: 2106

Answers (2)

Omar
Omar

Reputation: 31732

UPDATE

I came out with a better idea, using CSS3 animation. On vmouseover a class .marquee will be added to <a> and animate its' text. After the animation is done, everything will be changed to normal.

Demo here.

HTML

<div data-role="page" id="MessagesPage">
 <div data-role="header"> <a href="#HomePage" data-icon="home" data-  direction="reverse">Home</a> 
     <h1 id="ScheduleDayText">Messages</h1>

</div>
<div data-role="content">
    <ul data-role="listview" id="MessagesList" data-autodividers="false">
        <li date="2013-03-20"><a href="#">Lorem ipsum dolor sit amet.</a>

        </li>
        <li date="2013-03-20"><a href="#">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam laoreet ullamcorper vehicula. Cras eros augue, mollis vitae aliquet auctor, porta.</a>

        </li>
        <li date="2013-03-19"><a href="#">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum et.</a>

        </li>
    </ul>
 </div>
</div>

CSS + Animation

.marquee {
 white-space: nowrap !important;
 overflow: visible !important;
 animation: right-left 5s ease;
 -moz-animation: right-left 5s ease;
 -webkit-animation: right-left 5s ease;
}

@-moz-keyframes right-left {
0% {
    -moz-transform:translateX(0);
}
50% {
    -moz-transform:translateX(-50%);
 }
 100% {
    -moz-transform:translateX(-200%);
 }
}
/** Webkit Keyframes **/
 @-webkit-keyframes right-left {
 0% {
    -webkit-transform:translateX(0);
 }
 50% {
    -webkit-transform:translateX(-50%);
 }
 100% {
    -webkit-transform:translateX(-200%);
 }
}

JS

$("#MessagesList li").on('vmouseover', function (event) {
 var text = $(this).find('a').text();
 var textlength = $(this).find('a').text().length;
 var where = $(this).find('a');
 var root = $(this);
 if (textlength > 50) {
    where.addClass('marquee');
    where.css('text-overflow', '');
    //$("MessagesList").listview('refresh');
}
$("a").on('animationend animationend webkitAnimationEnd oanimationend MSAnimationEnd', function () {
    $(this).removeClass('marquee');
    //$("MessagesList").listview('refresh');
    $(this).css('text-overflow', 'ellipsis');
 });
});

OLD ANSWER

Well, I found a way to add <marquee> to scroll. However, I didn't test it on Mobile. I hope this works for you.

$("#MessagesList a").on('vmouseover vmouseout', function (event) {
 var text = $(this).text();
 if (event.type == 'vmouseover') {
  $(this).html('<marquee behavior="slide" direction="left">' + text + '</marquee>');
 }
 if (event.type == 'vmouseout') {
  $(this).text(text);
  $(this).find('marquee').remove();
 }
});

Upvotes: 3

Jaya Mayu
Jaya Mayu

Reputation: 17247

This is not exactly what you wanted but as you hover over the list it'll show the full content

$("#MessagesList a").bind('hover',function(event){
 $("#MessagesList a").css('white-space', 'nowrap');
 $(this).css('white-space', 'normal');
 $("#MessagesList").listview("refresh");
});

This is a live fiddle http://jsfiddle.net/mayooresan/w6wSC/

Upvotes: 3

Related Questions