简体   繁体   English

在 Jquery 自动完成中滚动文本

[英]Scroll Text in Jquery Autocomplete

I found the following fiddle which prevents any word wrap in autocomplete suggestions and only displays them in one line:我发现以下小提琴可以防止自动完成建议中的任何自动换行,并且只将它们显示在一行中:

http://jsfiddle.net/DwpZp/8/ http://jsfiddle.net/DwpZp/8/

 $("#ac").autocomplete({ source: [ "someveryve rylonglongword", "someveryverylong longwordsomeveryverylonglongword" ] });
 .ui-menu-item a { max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script> <link href="https://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" /> <div> <input type="text" id="ac" /> </div>

Is there any way to animate the autocomplete suggestions that overflow the max-width and to make them autoscroll from left to right on mouse hover?有什么方法可以使溢出最大宽度的自动完成建议动画化,并使它们在鼠标 hover 上从左向右自动滚动? Please see the following snippet with the example of the autoscroll on hover animation I would like to implement:请参阅以下代码段,其中包含我想实现的 hover animation 上的自动滚动示例:

 .labelContainer { height: 30px; border: 1px solid #000; border-radius: 3px; border-radius: 3px; display: flex; width: 200px; overflow: hidden; position: relative; padding: 5px; }.labelContainer span { position: absolute; white-space: nowrap; transform: translateX(0); transition: 1s; }.labelContainer:first-of-type:hover span { width: auto; transform: translateX(calc(200px - 100%)); }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="labelContainer"> <span>The long text should scroll when user hovers on it.</span> </div> <div class="labelContainer"> <span>Should Not Scroll</span> </div>

Try it like this像这样试试

 $("#ac").autocomplete({ source: [ "someveryve rylonglongword", "someveryverylong longwordsomeveryverylonglongword" ] });
 .ui-menu-item { overflow: hidden; position: relative; display: flex; max-width: 200px; white-space: nowrap; }.ui-menu-item a { white-space: nowrap; position: relative; transform: translateX(0); transition: transform 1s; box-sizing: border-box; }.ui-menu-item:hover a { width: auto; transform: translateX(calc(200px - 100%)); }.ui-widget-content a.ui-state-focus { margin: -1px; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.9.2/jquery-ui.min.js"></script> <link href="https://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" /> <div> <input type="text" id="ac" /> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM