0

我基于此 (http://tympanus.net/Tutorials/FancySlidingForm/) 为我的网站构建了一个表单。它在我的电脑上运行良好,并在 responsinator.com 等网站上进行了必要的调整,使其能够响应平板电脑、智能手机等。然而,主要是在 ipad 和智能手机的水平部分,第二个、第三个和第三个的标签和输入下一个选项卡是完全靠边的,而不是居中且不在屏幕上。

我在这里读到了一些关于 Jquery Mobile 的内容。我没有使用任何一个,只是这个:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

我是不是该?甚至 jquery mobile 也无法解决我的问题?

谢谢!

执行滑动部分的 Jquery 函数:

$(function() {
/*
number of fieldsets
*/
var fieldsetCount = $('#formElem').children().length;

/*
current position of fieldset / navigation link
*/
var current     = 1;

/*
sum and save the widths of each one of the fieldsets
set the final sum as the total width of the steps element
*/
var stepsWidth  = 0;
var widths      = new Array();
$('#steps .step').each(function(i){
    var $step       = $(this);
    widths[i]       = stepsWidth;
    stepsWidth      += $step.width();
});
$('#steps').width(stepsWidth);

/*
to avoid problems in IE, focus the first input of the form
*/
$('#formElem').children(':first').find(':input:first').focus(); 

/*
show the navigation bar
*/
$('#navigation_form').show();

/*
when clicking on a navigation link 
the form slides to the corresponding fieldset
*/
$('#navigation_form a').bind('click',function(e){
    var $this   = $(this);
    var prev    = current;
    $this.closest('ul').find('li').removeClass('selected');
    $this.parent().addClass('selected');
    /*
    we store the position of the link
    in the current variable 
    */
    current = $this.parent().index() + 1;
    /*
    animate / slide to the next or to the corresponding
    fieldset. The order of the links in the navigation
    is the order of the fieldsets.
    Also, after sliding, we trigger the focus on the first 
    input element of the new fieldset
    If we clicked on the last link (confirmation), then we validate
    all the fieldsets, otherwise we validate the previous one
    before the form slided
    */
    $('#steps').stop().animate({
        marginLeft: '-' + widths[current-1] + 'px'
    },500,function(){
        if(current == fieldsetCount)
            validateSteps();
        else
            validateStep(prev);
        $('#formElem').children(':nth-child('+ parseInt(current) +')').find(':input:first').focus();    
    });
    e.preventDefault();
});

/*
clicking on the tab (on the last input of each fieldset), makes the form
slide to the next step
*/


$('#formElem > fieldset').each(function(){
    var $fieldset = $(this);
    $fieldset.children(':last').find(':input').keydown(function(e){
        if (e.which == 9){
            $('#navigation_form li:nth-child(' + (parseInt(current)+1) + ') a').click();
            /* force the blur for validation */
            $(this).blur();
            e.preventDefault();
        }
    });
});

/*
validates errors on all the fieldsets
records if the Form has errors in $('#formElem').data()
*/
function validateSteps(){
    var FormErrors = false;
    for(var i = 1; i < fieldsetCount; ++i){
        var error = validateStep(i);
        if(error == -1)
            FormErrors = true;
    }
    $('#formElem').data('errors',FormErrors);   
}



/*
validates one fieldset
and returns -1 if errors found, or 1 if not
*/
function validateStep(step){
    if(step == fieldsetCount) return;

    var error = 1;
    var hasError = false;
    $('#formElem').children(':nth-child('+ parseInt(step) +')').find(':input:not(button)').each(function(){
        var $this       = $(this);
        var valueLength = jQuery.trim($this.val()).length;

    if(($this.attr('id')!='info_adicional') && ($this.attr('id')!='curriculum_vitae')) {
        if(valueLength == ''){
            hasError = true;
            //$this.css('background-color','#FFEDEF');
        }
    }
        //else
            //$this.css('background-color','#A8FC9C');  /* Campo preenchido */
    });
    var $link = $('#navigation_form li:nth-child(' + parseInt(step) + ') a');
    $link.parent().find('.error,.checked').remove();

    var valclass = 'checked';
    if(hasError){
        error = -1;
        valclass = 'error';
    }
    $('<span class="'+valclass+'"></span>').insertAfter($link);

    return error;
}
4

2 回答 2

0

如果唯一的问题是您的标签位置错位,您可能需要使用CSS 媒体查询来调整每个设备的 CSS。

有相当多的艺术可以让 CSS 在桌面和移动浏览器上看起来都很好:)

您可能还想检查这些链接:

  1. http://developer.android.com/guide/webapps/targeting.html
  2. http://www.metaltoad.com/sites/default/files/Responsive-Widths_0.png
  3. http://coding.smashingmagazine.com/2011/06/30/designing-for-android/

PS:jQuery Mobile 使用自己的(并且相当复杂的)CSS 和为移动使用量身定制的 JavaScript……它不是您自定义 CSS 的直接替代品

于 2012-09-27T13:57:18.483 回答
0

我认为您应该将 js 用于移动设备

http://jquerymobile.com/download/

于 2012-09-27T13:56:24.873 回答