您的位置:首页 > 其它

标题超过60个字符,显示省略号,鼠标移动到标题上面,显示全部标题的实现方式

2017-01-13 15:35 609 查看
第一种实现方式:鼠标移动到标题上面,弹出悬浮窗,用函数来实现。
<div class='requirement_css' onmouseover="overShow(this,event)" onmouseout="outHide()">

        <span class="m-l" ng-bind="item.name |cut:true:60:'...'">Task title</span>

    </div>

    <script>

        function overShow(obj, e) {

            var showDiv = document.getElementById('showDiv');

            var theEvent = e ? e : window.event;

            showDiv.style.left = theEvent.clientX + document.body.scrollLeft - 5 + "px";

            showDiv.style.top = theEvent.clientY + document.body.scrollTop - 50 + "px";

            showDiv.style.display = 'block';

            showDiv.innerHTML = obj.innerHTML;

        }

        function outHide() {

            var showDiv = document.getElementById('showDiv');

            showDiv.style.display = 'none';

            showDiv.innerHTML = '';

        }

    </script>

    <div id="showDiv"

         style=" position:absolute;width: auto;height:40px;font-size:16px;background-color:#f1f4f5;display: none "></div>

</accordion-heading>

另一种方法:在标题下方显示完整标题,使用AngularJs的自带的指令:ng-mouseenter和ng-mouseleave,注意,ng-mouseenter和ng-mouseleave要写在需要控制的标签内。
<div class='requirement_css' >

    <span ng-mouseenter="show=true" ng-mouseleave="show=false" class="m-l" ng-bind="item.name |cut:true:60:'...'">Task title</span>

</div>

<div   ng-show="show" style="padding:10px 0;font-size: 14px;line-height: 100% ; background-color:#f3f3f3; ">

    <a>{{ item.name }}</a>

</div>

定义的CSS样式
.requirement_css {

    width: 300px;

    height: 20px;

    font-size: 16px;

   

    overflow: hidden;

    text-overflow: ellipsis;

    white-space: nowrap;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐