728x90

2076

580

I have this input element:

<input type="text" class="textfield" value="" id="subject" name="subject">

Then I have some other elements, like other text inputs, textareas, etc.

When the user clicks on that input with #subject, the page should scroll to the last element of the page with a nice animation. It should be a scroll to bottom and not to top.

The last item of the page is a submit button with #submit:

<input type="submit" class="submit" id="submit" name="submit" value="Ok, Done.">

The animation should not be too fast and should be fluid.

I am running the latest jQuery version. I prefer to not install any plugin but to use the default jQuery features to achieve this.

javascript jquery

shareimprove this question

edited Sep 26 '17 at 12:18

Maistrenko Vitalii

9441613

asked Jul 13 '11 at 9:49

DiegoP.

18.6k2881100

add a comment

28 Answers

activeoldestvotes

3739

 

Assuming you have a button with the id button, try this example:

$("#button").click(function() { $([document.documentElement, document.body]).animate({ scrollTop: $("#elementtoScrollToID").offset().top }, 2000); });

I got the code from the article Smoothly scroll to an element without a jQuery plugin. And I have tested it on the example below.

<html> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <script> $(document).ready(function (){ $("#click").click(function (){ $('html, body').animate({ scrollTop: $("#div1").offset().top }, 2000); }); }); </script> <div id="div1" style="height: 1000px; width 100px"> Test </div> <br/> <div id="div2" style="height: 1000px; width 100px"> Test 2 </div> <button id="click">Click me</button> </html>

 Run code snippet

Expand snippet

shareimprove this answer

edited Jul 8 '18 at 14:48

php_nub_qq

7,350144397

answered Jul 13 '11 at 9:52

Steve

42k42637

  • 21

    This will not work in all cases. See stackoverflow.com/questions/2905867/… – Jānis Elmeris Apr 25 '12 at 14:43

  • 6

    @BarryChapman not exactly. After googling I've found this, so both tags are needed if you don't want to have extra logic per browser type. – s3m3n May 10 '13 at 0:01 

  • 69

    If you don't want animation, and instead want to jump instantly to the element, use .scrollTop(…) instead of .animate({scrollTop: …}, …). – Rory O'Kane Sep 20 '13 at 19:53 

  • 9

    In addition to you're solution (which works great), you can add an on complete function that adds the hashtag to the url. In this case it won't scroll, because the scrollTo already scrolled to the right position, and if a user copies the URL it will automatically snap to the right place on the page. – Sander Jan 23 '14 at 8:09

  • 7

    if you use a callback to run when the animation is complete and notice the callback fires twice with this solution, try using "$('html body').animate(..." instead of "$('html, body').animate(..." the comma created two animate events. one for html, one for body. you really just want one for the html body Thanks @T.J. Crowder stackoverflow.com/questions/8790752/… – BoatCode Mar 20 '15 at 16:17 

show 19 more comments

728x90

Adding custom scripts to Divi

Let’s say you’ve found a JavaScript (or jQuery, which is the “Write Less, Do More” JavaScript library) code snippet and you’d like to include it in your Divi website. There is a few ways you can go about doing it. One of options would be to use the Code Module.

Option 1 – Code Module

You need to make sure your code is wrapped in <script> </script> tags. Simply paste your code in the Code Module, like this:

 

 

 

  •  

  •  

  •  

  •  

  •  

 

 

 

This is the code used in the example above:

<script> jQuery(function($){ alert('Hi! This is working!'); }); </script>

Using Code Module is a good option if you want your code to run only on one specific page. But if you want your code to run on every page, it would be better to add it to the <head> tag of your website via Theme Options.

Option 2 – Divi Theme Options

To add a code to every page navigate to Divi Theme Options > Integration tab.  Make sure the “Enable header code” option is checked, and paste your code below.

 

 

 

  •  

  •  

  •  

  •  

  •  

 

 

 

You can also place your code in a file with JS extension (e.g. my-scripts.js) and use this method to include it. You would need to login to your WordPress site via FTP or cPanel, whichever method you prefer. If you’re using cPanel, go to File Manager to access your site’s files. Locate your child theme folder and create a js folder in it and upload your file inside of this folder. The url for your file will look something like this: http://yoursite.com/wp-content/themes/yourchildtheme/js/my-scripts.js

To get your site to load external JS file (e.g. your own code or some jQuery plugin) add a code like this with modified url source.

<script src="http://yoursite.com/wp-content/themes/yourchildtheme/js/my-scripts.js"></script>

  •  

  •  

  •  

  •  

  •  

The last method is a bit more advanced, but it is the approach recommended by WordPress.

Option 3 – Enqueuing scripts via functions.php

With this example I’m assuming you are using a Divi Child Theme and you uploaded your scripts file to “js” folder inside your child theme files. You can add the code below to your functions.php file:

function mycustomscript_enqueue() { wp_enqueue_script( 'custom-scripts', get_stylesheet_directory_uri() . '/js/my-scripts.js' ); } add_action( 'wp_enqueue_scripts', 'mycustomscript_enqueue' );

If your script relies on jQuery library you can modify it like this to make sure jQuery will be loaded as well:

function mycustomscript_enqueue() { wp_enqueue_script( 'custom-scripts', get_stylesheet_directory_uri() . '/js/my-scripts.js', array( 'jquery' )); } add_action( 'wp_enqueue_scripts', 'mycustomscript_enqueue' );

Just don’t forget to change this code to match your file name.

And that’s it – you’ve successfully loaded custom JavaScript to your divi website 🙂

728x90

UPDATE xe_documents SET content=REPLACE(content, "바꿀내용에 쌍따옴표가", "가능할까요?");

 

바꿀내용에 쌍따옴표가 있는데 검색이 될까요?

 

감사합니다.

 0좋은질문

 

댓글 9

 

 

 

 

 

 

 

      • 2016.10.25 10:16:45
     

    엔터로 쓰이는 n이 특별한 경우에요.

    \뒤에 오는 문자는 어떠한 역할을 하지 말고 문자 그대로 써라 그런 의미이거든요.

    그래서 따옴표를 넣고 싶으면 \" 이렇게 하면 되요.

    예를 들면
    \\\"
    이렇게 하면
    \"가 되는 거구요.

    첫번째 \는 문자를 문자 그대로 표기하라는 명령, 두번째 \는 첫번째 \에 의해서 \로 인식되구요
    세번째 \는 문자를 문자 그대로 표기하라는 명령, 네번째 "는 첫번째 \에 의해서 "로 인식되죠.

    설명이 어려울려나요..-0-;;;

    좋은답변1

 

 

  •  
    • 질문자
      • 2016.10.25 10:24:02
     

    감사합니다.

    frameborder="0" scrolling="no" width="170" height="170"


    frameborder=\"0\" scrolling=\"no\" width=\"170\" height=\"170\"
    로 표시하면 되는거죠? db 다보니 조심스럽네요 ㅠ

 

 

      • 2016.10.25 10:19:38
     

    UPDATE xe_documents SET content=REPLACE(content, '바꿀내용에 쌍따옴표가', '가능할까요?');

 

 

  •  
    • 질문자
      • 2016.10.25 10:27:18
     

    작은 따옴표로 하는것도 방법이긴 하겠네요.

 

 

  • ?
      • 2016.10.25 10:23:00
     

    UPDATE xe_documents SET content=REPLACE(content, "바꿀내용에 \"쌍따옴표\"가", "가능할까요?");

    이런 식으로 하면 됩니다.

    원래 SQL 문에서 "는 문자열을 묶어서 표시할 때 사용하는데, 실제 쌍따옴표(")라는 문자열을 그대로 사용해야할 경우 원래 의미와 중복되어서 의미가 모호하게 됩니다. 백슬래시(\)라는 기호를 앞에 넣어서 이건 쌍따옴표 문자 그대로 해석하라는 의미입니다.

    좋은답변1

 

 

  •  
    • 질문자
      • 2016.10.25 10:26:57
     

    완전 잘됩니다 모두들 너무 감사드립니다. ^^

 

'WEB > WP(WordPress)' 카테고리의 다른 글

MangBoard  (0) 2019.05.22
How to add JavaScript & jQuery code to Divi Theme  (0) 2019.05.20
What is the ideal image size for Divi Websites?  (0) 2019.05.05
서울시체를 웹폰트로 사용하기 in WP  (0) 2019.05.05
The Divi Login Module  (0) 2019.05.03
728x90

The behaviour of these functions is affected by settings in php.ini.

PHP Options/Inf Configuration OptionsNameDefaultChangeableChangelog

assert.active "1" PHP_INI_ALL  
assert.bail "0" PHP_INI_ALL  
assert.warning "1" PHP_INI_ALL  
assert.callback NULL PHP_INI_ALL  
assert.quiet_eval "0" PHP_INI_ALL  
assert.exception "0" PHP_INI_ALL Available since PHP 7.0.0.
enable_dl "1" PHP_INI_SYSTEM This deprecated feature will certainly be removed in the future.
max_execution_time "30" PHP_INI_ALL  
max_input_time "-1" PHP_INI_PERDIR Available since PHP 4.3.0.
max_input_nesting_level "64" PHP_INI_PERDIR Available since PHP 5.2.3.
max_input_vars 1000 PHP_INI_PERDIR Available since PHP 5.3.9.
magic_quotes_gpc "1" PHP_INI_PERDIR PHP_INI_ALL in PHP <= 4.2.3. Removed in PHP 5.4.0.
magic_quotes_runtime "0" PHP_INI_ALL Removed in PHP 5.4.0.
zend.enable_gc "1" PHP_INI_ALL Available since PHP 5.3.0.

For further details and definitions of the PHP_INI_* modes, see the Where a configuration setting may be set.

Here's a short explanation of the configuration directives.

assert.active boolean

Enable assert() evaluation.

assert.bail boolean

Terminate script execution on failed assertions.

assert.warning boolean

Issue a PHP warning for each failed assertion.

assert.callback string

User function to call on failed assertions.

assert.quiet_eval boolean

Use the current setting of error_reporting() during assertion expression evaluation. If enabled, no errors are shown (implicit error_reporting(0)) while evaluation. If disabled, errors are shown according to the settings of error_reporting()

assert.exception boolean

Issue an AssertionError exception for the failed assertion.

enable_dl boolean

This directive is really only useful in the Apache module version of PHP. You can turn dynamic loading of PHP extensions with dl() on and off per virtual server or per directory.

The main reason for turning dynamic loading off is security. With dynamic loading, it's possible to ignore all open_basedir restrictions. The default is to allow dynamic loading, except when using safe mode. In safe mode, it's always impossible to use dl().

max_execution_time integer

This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0.

The maximum execution time is not affected by system calls, stream operations etc. Please see the set_time_limit() function for more details.

You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.

Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.

max_input_time integer

This sets the maximum time in seconds a script is allowed to parse input data, like POST and GET. Timing begins at the moment PHP is invoked at the server and ends when execution begins. The default setting is -1, which means that max_execution_time is used instead. Set to 0 to allow unlimited time.

max_input_nesting_level integer

Sets the max nesting depth of input variables (i.e. $_GET, $_POST.)

max_input_vars integer

How many input variables may be accepted (limit is applied to $_GET, $_POST and $_COOKIE superglobal separately). Use of this directive mitigates the possibility of denial of service attacks which use hash collisions. If there are more input variables than specified by this directive, an E_WARNING is issued, and further input variables are truncated from the request.

magic_quotes_gpc boolean

Warning

This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

Sets the magic_quotes state for GPC (Get/Post/Cookie) operations. When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically.

Note:

If the magic_quotes_sybase directive is also ON it will completely override magic_quotes_gpc. Having both directives enabled means only single quotes are escaped as ''. Double quotes, backslashes and NUL's will remain untouched and unescaped.

See also get_magic_quotes_gpc()

magic_quotes_runtime boolean

Warning

This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

If magic_quotes_runtime is enabled, most functions that return data from any sort of external source including databases and text files will have quotes escaped with a backslash. If magic_quotes_sybase is also on, a single-quote is escaped with a single-quote instead of a backslash.

Functions affected by magic_quotes_runtime (does not include functions from PECL):

zend.enable_gc boolean

Enables or disables the circular reference collector.

 add a note

User Contributed Notes 3 notes

up

down

26

rubo77 

5 years ago

I think it is important to mention that some distributions apply bugfixes for older versions so "Available since PHP 5.3.9" is not reliable, for example:
debian squeeze implemented the directive max_input_vars in PHP 5.3.3-7+squeeze7 (see http://ftp-master.metadata.debian.org/changelogs/main/p/php5/php5_5.3.3-7+squeeze17_changelog )

up

down

-2

horst at pepperzak.com 

7 years ago

Caution: Although magic_quotes_gpc is flagged as dreprecated the default value is still "ON". So you will explicitly have to put

magic_quotes_gpc = Off

into your php.ini. Commeting out the magic_quotes_gpc-line will not turn magic_quotes_gpc off.

up

down

-71

Anonymous 

5 years ago

The max_input_vars limit can be overcome by reading the input in raw, i.e.:
<?php
  $sRawInputData
= fopen( 'php://input' );
?>

+ Recent posts