2

更新 我有一个 jsfiddle 在这里显示问题:http: //jsfiddle.net/waf11s6u/1/当您在搜索栏中键入一个字母时,附加到 div 的自定义滚动条消失。滚动条可能会被从 div 中淡出不匹配单词的代码淡出?

~~

我正在为 Facebook 游戏创建一个自定义的多好友选择器,它看起来类似于:http ://tinyurl.com/gus79cf 用户可以在搜索栏中键入,任何匹配的好友名称都会出现在下面的区域中。我正在使用自定义滚动条插件来设计滚动条以向下滚动朋友列表。这是插件的网站: http: //manos.malihu.gr/jquery-custom-content-scroller/

视觉上滚动条由两部分组成,第一部分是轨道(我已经在背景图像上绘制了轨道,所以它实际上不是 Javascript 代码的一部分),第二部分是图标,图标是沿着轨道上下移动的小图像。

滚动条完美地工作(意味着图标可以正确地上下滑动),除了一件事,每当用户在搜索栏中输入一个字母时,图标就会消失,只有当搜索栏为空时它才会再次可见。

包含朋友姓名和图像的 div 是在 Javascript 中动态创建的(称为“mfsForm”)。当用户开始输入姓名时,我有一些 Javascript 会淡出不匹配的朋友姓名和图像。

我认为这段代码也导致图标消失。

这是有问题的代码:

  // Earlier code here connects to Facebook's API.
  // Then get the list of friends for this user with the Graph API
            FB.api('/me/invitable_friends?limit=48', function(response) {
                var container = document.getElementById('mfs');
  // Creating the div "mfsForm" (this will hold the friend names & photos, and is also what the custom scrollbar is applied to.)
                    var mfsForm = document.createElement('form');
                    mfsForm.id = 'mfsForm';
                    mfsForm.className = " mCustomScrollbar mfsForm";

                // Iterate through the array of friends object and create a checkbox for each one.
                for (var i = 0; i < response.data.length; i++) { //Math.min(response.data.length, 10)

                    var friendItem = document.createElement('div');  
                    friendItem.id = 'friend_' + response.data[i].id;
                    friendItem.style.cssText="width:100px; height:100px; padding:7px; color:#FFF;"
                    friendItem.style.cssFloat="left";
                    friendItem.innerHTML = '<input type="checkbox" name="friends" value="' + response.data[i].id + '" />';

                    var img = document.createElement('img');
                    img.src = response.data[i].picture.data.url;
                    img.style.cssText = 'width: 70px;height: 70px;'
                    friendItem.appendChild(img);

                    var labelName = document.createElement('label');
                    labelName.style.cssText = 'font-size: 14px;'
                    labelName.innerHTML = response.data[i].name;
                    friendItem.appendChild(labelName);

                    mfsForm.appendChild(friendItem);
                }
                container.appendChild(mfsForm);
                console.log(mfsForm);               
                $(mfsForm).mCustomScrollbar();

                // Create a button to send the Request(s)
                var sendButton = document.createElement('div');
                sendButton.id = 'sendButton';
                sendButton.onclick = sendRequest;
                container.appendChild(sendButton);

                $("#filter").keyup(function(){

        // Retrieve the input field text and reset the count to zero
        var filter = $(this).val()//, count = 0;

        // Loop through the comment list
        $("#mfsForm div").each(function(){

            // If the list item does not contain the text phrase fade it out
            if ($(this).text().search(new RegExp(filter, "i")) < 0) {
                $(this).fadeOut("slow");


            // Show the list item if the phrase matches and increase the count by 1
            } else {
                $(this).show();

                //Attempting to fade in the icon here:
                $(this).next('.mCSB_dragger_bar').fadeIn("slow"); 

                }
            });
        })
                });

我认为这$(this).fadeOut("slow");会使滚动条图标淡出。我试图通过引用其类(mCSB_dragger_bar)并将其淡入此处来定位图标: $(this).next('.mCSB_dragger_bar').fadeIn("slow");但它不起作用。

任何有关我可以尝试解决此问题的帮助或建议将不胜感激,在此先感谢您!

4

2 回答 2

0

问题是什么?您没有显示正常代码来查看脚本删除图标的位置,我可以说您强制脚本显示此图标。把输入代码onchange="f()"或onkey pres或其他。和

<script>
function f(){ //$('#icon') the element witch contain icon that disapear
$('#icon').css('visibility','visible').css('display','block');
$('#icon').attr('background','url('/icon.png')')}`
/*$('#parent-of-icon').appendChild(icon );*/

其他取决于图标消失的原因。
可能是您的脚本删除图标(html 元素)然后创建它。

在此模式下,图标将始终出现在每次按键上。

于 2016-01-26T12:48:53.770 回答
0

尽量$(this).find('.mCSB_dragger_bar').fadeIn("slow");不要$(this).next('.mCSB_dragger_bar').fadeIn("slow");

如果mCSB_dragger_bar$(this) 元素($this -> $("#mfsForm div") -> some div's on element with id=mfsForm)上存在具有类名的元素,它将找到并显示;

NEXT 只返回 $this 之后的一个元素,可能在 $(this) 之间并mCSB_dragger_bar存在另一个元素。

也试试$(this).parent().find('.mCSB_dragger_bar').fadeIn("slow");if mCSB_dragger_barand $(this) is on the same doom level

于 2016-01-26T14:53:37.060 回答