doujiyan0971 2017-11-25 23:38
浏览 64

使用jquery .load()函数从PHP文件加载图像时,jQuery Drag&Drop无法正常工作

i have a tabbed box with two tabs, one that contains "characters" and one that contains "weapons". if i load the images into their respective containers using PHP directly inside my HTML, the images drag fine, but i can't get both containers to load their contents; it only loads the contents retrieved by the first instance of PHP code. when i put the respective codes into separate php files and use .load(), though, the contents load fine, but are no longer draggable.

HTML for the tab box:

<div class="tabBox">
    <ul class="tabs">
        <li class="card-gallery" active>Cards</li>
        <li class="weapon-gallery">Weapons</li>
    </ul>
    <div class="tabContainer">
        <div id="card-gallery" class="tabContent">
        </div>

        <div id="weapon-gallery" class="tabContent">
        </div>
    </div>
</div>

jQuery script to make the tabs work:

$(".tabContent").hide();
$('#card-gallery').load('cardgallery.php');
$('#weapon-gallery').load('weaponsgallery.php');

$(".tabContent").eq(0).show();
$(".tabs li").on('click', function(event) {
    var showTab = $(this).attr('class')
    if (showTab == 'card-gallery') {
        $('.tabContent').hide();
        $('#card-gallery').show();
        $(this).siblings().removeAttr('active');
        $(this).attr('active',true);
    } else if (showTab == 'weapon-gallery') {
        $('.tabContent').hide();
        $('#weapon-gallery').show();
        $(this).siblings().removeAttr('active');
        $(this).attr('active',true);
    }
});

jQuery draggable (currently only for "characters" tab):

$("#card-gallery .draggable").draggable({
    containment: "document",
    helper: "clone",
    appendTo: 'body',
    scroll: false
});

PHP for loading images:

    <?php
        $db = new mysqli("localhost", "____", "____", "builder")
            or die('Error connecting to MySQL server.');

        $result = mysqli_query($db, 'SELECT id, i_card_type, name, i_character,
        i_rarity, i_weapon, image, special_icon
        FROM card_data
        LIMIT 1,200');

        $i=0;

        while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
            if (strpos($row[2], '(') !== false) {                                                                   
                $cardtitle = preg_split("/(【|】|\(|\))/u", $row[2]);                                                 
            } else {                                                
                $cardtitle = preg_split("/(【|】)/u", $row[2]);                                                       
            }

            if ($i++ % 3 == 0) echo '<div class="row">';            
                echo '<div class="card-box">';                      
                    echo '<div id="' . $row[0] . '" class="draggable" 
                    data-card-type="' . $row[1] . '"data-cid="' . $row[3] . '" 
                    data-wid="' . $row[5] . '" data-rarity="' . $row[4] . '">';
                        echo '<div class="icon-box">';                                                              
                            echo '<div class="invalid-card-text"></div>';                                           
                                echo '<div class="icon-image">';                                                    
                                    echo '<img src="' . $row[6] . '" />';                                               
                                    if ($row[7] != 'NULL') {
                                    echo '<img class="sicon" src="' . $row[7] . '" />';
                                    }
                                    echo '<img class="wicon" src="weapons/img/type/' . $row[5] . '.png" />';
                                echo '</div>';
                            echo '</div>';
                        echo '</div>';
                    echo '<p class="card-name">';                                                                   
                        echo '【<b>' . $cardtitle[1] . '</b>】';                                                      
                        echo '<br />';
                        echo $cardtitle[2];                                                                         
                        if (strpos($row[2], '(') !== false) {   
                            echo '<br />';
                            echo '<p class="small">( ' . $cardtitle[3] . ' )</p>';                              
                        }
                    echo '</p>';
            echo '</div>';
        if ($i % 3 == 0) echo '</div>';                                                                         
    }
?>
  • 写回答

1条回答 默认 最新

  • douping3427 2017-11-25 23:51
    关注

    nevermind, my bad, i figured it out just a few minutes after posting this. both

    $('#card-gallery').load('cardgallery.php', function() {
        $('.draggable').draggable({
            containment: "document",
            helper: "clone",
            appendTo: 'body',
            scroll: false
        });
    }); 
    

    &

    function allowDrag() {
        $('.draggable').draggable({
            containment: "document",
            helper: "clone",
            appendTo: 'body',
            scroll: false
        });
    }
    
    $('#card-gallery').load('cardgallery.php', allowDrag)
    

    work.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀